private void Send() { UdpClient udpClient = null; IPEndPoint serverEP = null; try { udpClient = new UdpClient(); serverEP = new IPEndPoint(IPAddress.Parse("xxx.xxx.xxx.xxx"), 1234); byte[] b = ASCIIEncoding.ASCII.GetBytes("This is a test"); int bSent = udpClient.Send(b, b.Length, serverEP); if (bSent == b.Length) MessageBox.Show("Success"); else throw new ApplicationException("Byte count failed"); } catch (Exception ee) { MessageBox.Show(ee.Message); } }
UdpClient - Compact and Full Framework
Hi,
Please take a look at the code below. When compiled as a Windows application (.NET 2.0), the Send method will not succeed when there is no network connection. The System.Net.Sockets.SocketException (A socket operation was attempted to an unreachable host) is thrown. However, when the same code is compiled with Compact Framework 2.0, the Send method always succeeds!
Is there a way to mimic the Full Framework behavior on Compact Framework My application is supposed to send GPS messages using UDP. If the sending fails (no connectivity for example), the message should be stored, and send later. Since the messages will be sent quite frequently, I don't want to manually check connectivity before each call of the Send method.
Thanks in advance for any ideas.

UdpClient - Compact and Full Framework
Alexey Nayda
Alex,
Thanks for your response, but I think you are missing the point. You could expect that the same code compiled for Full and Compact framework would behave at least similarly.
Code_Explorer
The UDP is by nature is a stateless protocol. If you don't want to use the statefull TCP, you will need to implement any kind confirmation message (it's usually called ACK) that is send from the receiving side after a package is received. Not receiving this message, will be an indication that you need to buffer up your messages.
Joel Martinez
Let's say device does have network connection all the time (e.g. loop back interface), wouldn’t that mean they do behave the same If you install something like vxUtils I’m fairly confident it would show device has loop back address even if network is out.
Regardless, I believe it’s you who’s missing the point Alex has. You’re using UDP so don’t expect any checks done including network presence (which might or might not be possible due to hardware and/or drivers differences).
sqlnewbee
Thanks Ilya. The difference is in the loop back address (the device has it, and PC doesn't).
I don't negate what Alex wrote and what I already knew. My post was more about what causes UDPClient to behave differently.