Hi all,
I'm writing a UDP program and I'd like to have the socket time out if it doesn't 
recieve an answer in n milliseconds.

What I do is send a packet to a UDP server, which is fine, everything works ok...

but then I want to wait n milliseconds for a reply, and if I don't get a reply then 
handle accordingly. However, with my current code, my code hangs if I don't get a 
reply back from the server.  Does anyone know what I need to change?

Here is my code...

//sending the packet, works great!
byte[] PacketToSend = BuildPacket();
IPAddress address = Dns.Resolve( serverAddress  ).AddressList[0];
Socket s = new Socket( AddressFamily.InterNetwork,SocketType.Dgram,ProtocolType.Udp);
s.SendTo( PacketToSend, 0, PacketToSend.Length, SocketFlags.None, new IPEndPoint( 
address, _Port ) );



//works great if the packet comes back, but
//hangs up if the response packet is never rec'd
m_UdpPacket = new Byte[ m_Length ];
IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);
EndPoint tempRemoteEP = (EndPoint)sender;
s.ReceiveFrom( m_UdpPacket, 0, m_Length , SocketFlags.None, ref tempRemoteEP );


Thanks in advance,
Dave

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to