Problems with UDP

H

Houston Keach

I seem to be having all sorts of problems with UDP that I don't
encounter with TCP. I realize that ActiveSync doesn't pass UDP
packets but it seems that the following scenarios should work.

1. I started out with the UdpClient class, intending just to quickly
test connectivity. Can't get the simplest code to work:

System.Net.Sockets.UdpClient udpListener = new UdpClient();
if(udpListener == null) return ;
IPEndPoint remoteEndPoint = new IPEndPoint( IPAddress.Any, 6681);
byte[] recvBytes = udpListener.Receive(ref remoteEndPoint);
string returnData = System.Text.Encoding.ASCII.GetString(recvBytes, 0,
recvBytes.Length);

On the call to Receive I get this exception:

An unhandled exception of type 'System.Net.Sockets.SocketException'
occurred in system.dll
Additional information: An invalid argument was supplied.

2. I gave up on the UdpClient and used the Socket class. Code that
works great in the full framework, executes on the device but doesn't
seem to get any packets. Clients trying to send packets to the UDP
port report that it's not open. When I run it in the emulator,
netstat doesn't show the port being open. Is it even possible to
receive UDP datagrams through the emulator?

3. Gave up on the emulator and tried to test on the device using the
wireless network. Connectivity is good but, again, no UDP packets! I
can send but not receive. Clients don't think there is an open port.

Hoping someone can offer some advice. Thanks in advance.

--Houston Keach
 
M

Mark Hudson

Houston,
For what it's worth:
I got UDP working (like you, using Sockets, not UdpClient) with a wireless
connection.

I have to explicitly select the local AND remote address AND port, and the
Bind() AND Connect() at both ends!
eg Both were explicitly set for local address with the common subnet (in my
case the auto-DHCP 169.354.x.x), and both on port 4568 as per a demo I read
somewhere.

This worked iff the above conditions were met. I'm now experimenting with
two way comms...

Mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top