I am developing an application where there is a source which sends UDP datagrams at a constant Interval (2 datagrams per second). I am receiving these datagrams in the following code:
Expand|Select|Wrap|Line Numbers
- EP = New IPEndPoint(IPAddress.Any, clsUDP.nListenOnPort)
- (' clsUDP.nListenOnPort=6466)
- UDPInput = New UdpClient(EP)
- While clsMisc.ListenforUDP
- Try
- byt = UDPInput.Receive(EP)
- ..................
- Catch ex As Exception
- MessageBox.Show(ex.ToString)
- End Try
- End While
- UDPInput.Close()
- UDPInput = Nothing
- EP = Nothing
This is working properly when a user logs in and logs off three times consecutively. But when an user logs in fourth time. I found out by debugging that the program hangs
after
byt = UDPInput.Receive(EP)
this line. I have also tried with asynchronous connection (Beginreceive and end receive) and also with
UDPInput.Client.SetSocketOption(SocketOptionLevel. Socket, SocketOptionName.ReceiveBuffer, 0) to flush the buffer before I read the byt but in vain. It is always the fourh time that the problem arises.
I am trying this to solve for the last 3 days without success. I shall be grateful if somebody helps me.
Thanks.
Roy