D
David
I’m trying to use a UDP socket, but it isn’t working.
Here’s stripped down code of what I’m trying to do:
public void BindASocket()
{
System.Net.Sockets.UdpClient udpreceiver;
System.Net.IPEndPoint localreceiver;
System.Net.IPAddress localip;
localip = System.Net.IPAddress.Parse(tbLocalIP.Text);
localreceiver = new System.Net.IPEndPoint(localip, 0);
udpreceiver = new System.Net.Sockets.UdpClient();
udpreceiver.Client.Bind(localreceiver);
}
What I want to do is set up a receiver, and then tell it to receive whatever
comes its way. I create the receiver, and I want to bind it to an address,
which I type into a text box on a form. When I run the above, no matter what
IP address I put into the box, I get an excpetion with the message:
The requested address is not valid in its context
I’ve tried the local address of the PC, something that isn’t the local
address, “anyâ€, and a few others, but always I get the same error.
It looks like a perfectly good address, so what would be valid in that
context.
Also, what I really want to do is just call either “receive†or
“beginreceiveâ€, and start getting messages. However, when I do that, I get
an exception that says I have to do a Bind operation before calling Receive.
The examples on MSDN don’t have a bind step, so I’m a bit confused about that
as well.
Here’s stripped down code of what I’m trying to do:
public void BindASocket()
{
System.Net.Sockets.UdpClient udpreceiver;
System.Net.IPEndPoint localreceiver;
System.Net.IPAddress localip;
localip = System.Net.IPAddress.Parse(tbLocalIP.Text);
localreceiver = new System.Net.IPEndPoint(localip, 0);
udpreceiver = new System.Net.Sockets.UdpClient();
udpreceiver.Client.Bind(localreceiver);
}
What I want to do is set up a receiver, and then tell it to receive whatever
comes its way. I create the receiver, and I want to bind it to an address,
which I type into a text box on a form. When I run the above, no matter what
IP address I put into the box, I get an excpetion with the message:
The requested address is not valid in its context
I’ve tried the local address of the PC, something that isn’t the local
address, “anyâ€, and a few others, but always I get the same error.
It looks like a perfectly good address, so what would be valid in that
context.
Also, what I really want to do is just call either “receive†or
“beginreceiveâ€, and start getting messages. However, when I do that, I get
an exception that says I have to do a Bind operation before calling Receive.
The examples on MSDN don’t have a bind step, so I’m a bit confused about that
as well.