Non-Blockig UDP ?

  • Thread starter Thread starter Axel Stallknecht
  • Start date Start date
A

Axel Stallknecht

Hi folks,

I try to realize a little networkclient, which is fetching network messages.
I do this with :

Byte[] receiveBytes = udpclient.Receive(ref RemoteIpEndPoint);

But because udpclient.Receive is blocking until data arrives, I cannot close
the application.
Does anyone realised a Non-Blocking UDPClient or have an other useful
solution ?
Thanks in advance.

cu
Axel
 
That, by itself, doesn't fix anything. It just defers the issue to "I can't
exit my application because a thread is still running". The basic answer is
that you need to close the socket over which the network communication is
occurring. I haven't done much UDP stuff in CF, but you might try calling
Close() on the UDPClient instance from another thread to close the socket,
which should, in turn, cause the Receive call to end with an error.

Paul T.

Daimy said:
You can use Thread.



Axel Stallknecht said:
Hi folks,

I try to realize a little networkclient, which is fetching network messages.
I do this with :

Byte[] receiveBytes = udpclient.Receive(ref RemoteIpEndPoint);

But because udpclient.Receive is blocking until data arrives, I cannot close
the application.
Does anyone realised a Non-Blocking UDPClient or have an other useful
solution ?
Thanks in advance.

cu
Axel
 
Axel Stallknecht said:
Hi folks,

I try to realize a little networkclient, which is fetching network messages.
I do this with :

Byte[] receiveBytes = udpclient.Receive(ref RemoteIpEndPoint);

But because udpclient.Receive is blocking until data arrives, I cannot close
the application.
Does anyone realised a Non-Blocking UDPClient or have an other useful
solution ?
Thanks in advance.

We do this by placing the receive logic in a thread and looking to see if
there are any received bytes every 300ms. If so, we go get them. This
method allows us to work around the limitations with the compact frameworks.
Other wise we would simply do a receive with wait. Also, this method allows
you to cleanly exit the thread when needed.

Mark
 
You should look into the Socket.Poll() call. We create a thread that loops
on this, and when it returns true we know that the socket has data (well, it
also returns true when the socket closes, but then we can test for
socket.available to see if it was that case). This is working for TCP. We
have not tried it for UDP.



Paul G. Tobey said:
That, by itself, doesn't fix anything. It just defers the issue to "I
can't exit my application because a thread is still running". The basic
answer is that you need to close the socket over which the network
communication is occurring. I haven't done much UDP stuff in CF, but you
might try calling Close() on the UDPClient instance from another thread to
close the socket, which should, in turn, cause the Receive call to end
with an error.

Paul T.

Daimy said:
You can use Thread.



Axel Stallknecht said:
Hi folks,

I try to realize a little networkclient, which is fetching network messages.
I do this with :

Byte[] receiveBytes = udpclient.Receive(ref RemoteIpEndPoint);

But because udpclient.Receive is blocking until data arrives, I cannot close
the application.
Does anyone realised a Non-Blocking UDPClient or have an other useful
solution ?
Thanks in advance.

cu
Axel
 
Back
Top