B
Ben
Hello,
I'm writing an application which communicate by UDP protocol from a
PocketPC to a computer. I have to verify if the server (computer) is
still available, or when I'm trying to connect (UdpClient.Connect),
the application freezes. Since I can't catch any exception with the
Connect function, I would like to create a "ping request", using the
Socket class, which verify every x seconds if the server is available.
Here is a bit of my code :
IPEndPoint endPoint = new
IPEndPoint(IPAddress.Parse("10.102.100.127"), 9000);
EndPoint PingEndPoint = (EndPoint)endPoint;
byte[] msg = new byte[1] {1};
ping = new Socket(AddressFamily.InterNetwork, SocketType.Dgram,
ProtocolType.Udp);
try
{
ping.SetSocketOption(SocketOptionLevel.Udp,
SocketOptionName.SendTimeout, 2000);
}
catch (SocketException se)
{
MessageBox.Show(se.ToString() + " " + se.ErrorCode);
}
try
{
ping.SendTo(msg, PingEndPoint);
}
catch (Exception so)
{
// Here it would tell me that the server is offline
MessageBox.Show(so.ToString());
}
I'm having a SocketException in the first try-catch block :
An invalid argument was supplied 10022
Does anyone can tell me how to proceed correctly?
Thanks in advance...
I'm writing an application which communicate by UDP protocol from a
PocketPC to a computer. I have to verify if the server (computer) is
still available, or when I'm trying to connect (UdpClient.Connect),
the application freezes. Since I can't catch any exception with the
Connect function, I would like to create a "ping request", using the
Socket class, which verify every x seconds if the server is available.
Here is a bit of my code :
IPEndPoint endPoint = new
IPEndPoint(IPAddress.Parse("10.102.100.127"), 9000);
EndPoint PingEndPoint = (EndPoint)endPoint;
byte[] msg = new byte[1] {1};
ping = new Socket(AddressFamily.InterNetwork, SocketType.Dgram,
ProtocolType.Udp);
try
{
ping.SetSocketOption(SocketOptionLevel.Udp,
SocketOptionName.SendTimeout, 2000);
}
catch (SocketException se)
{
MessageBox.Show(se.ToString() + " " + se.ErrorCode);
}
try
{
ping.SendTo(msg, PingEndPoint);
}
catch (Exception so)
{
// Here it would tell me that the server is offline
MessageBox.Show(so.ToString());
}
I'm having a SocketException in the first try-catch block :
An invalid argument was supplied 10022
Does anyone can tell me how to proceed correctly?
Thanks in advance...