UDP comms and blocking of Port

  • Thread starter Thread starter Zahid
  • Start date Start date
Z

Zahid

Hi,

Im using UDP communications to send and receive data
wirelessly. Im also reading the book "Microsoft .Net
Compact Framework" by Eric Rubin and Ronnie Yates. The
example given has the following command:

data = listener.receive(receivedIPInfo)

It states that this command "blocks and listens on port
8587 - also defined. Does this mean that if I have
another thread in my app that sends data to the same
port - it will be unable to send data until the above
command receives data ? Or can I still send data? If so
My app could be waiting for a long time before data is
received yet it may want to send data whilst waiting for
data (ie it cant be full duplex). Am i misunderstanding
this?

Basically I want to create 2 threads that run in the
background of my app. One that listens for data at a
specific IPAddresses port and one that sends data to the
same port. Whats the best way to do this ? It is
possible with UDP isnt it?


Thanks in advance.
Thanks.
 
Yes, this is possible. It is a full duplex connection.

--
Remove "user" from the email address to reply to the author.

This posting is provided "AS IS" with no warranties, and confers no rights

Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
 
There were some comments in here about problems with UDP and wireless
connections (but yes, sockets should be all bi-directional):

Here was what was written previously
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

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



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

<Houston Keach> wrote in message
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
 
Back
Top