Re: Ping request UDP C# PocketPC

From: Paul G. Tobey [eMVP] (ptobey)
Date: 03/10/05


Date: Thu, 10 Mar 2005 16:35:50 -0700

I think that send time-out is not settable on Windows CE, hence the error.
I'm not sure what a UDP send time-out would mean anyway, though.

I'd go back to the UdpClient-based code and figure out why Connect() is not
returning. There's no such thing as a 'connected' UDP socket. It's a
datagram protocol. There's no state in the connection. Connect(), as far
as I can tell, should return immediately having done nothing but save the
port number and IPAddress that you passed to it.

Your 'ping' code wouldn't do anything, even if the send time-out meant
something. There's no response from the other end of a UDP datagram send
mandated. Unless your *code* running on the other end responds, as PING's
peer program does, you won't ever get anything back.

Paul T.

"Ben" <benoit.rheaume@gmail.com> wrote in message
news:de368bad.0503101522.244b17c7@posting.google.com...
> 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...



Relevant Pages

  • Re: Strange UDP Socket problem
    ... You can catch that exception and move on. ... never get any udp reply back to post an exception. ... >> I suspect you would get the same response if you used one thread to send ... >> thread on same socket. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Strange UDP Socket problem
    ... thread on same socket. ... > It's my understanding of UDP sockets that if there is a thread blocked on ... my "recvFrom" call throws an exception. ... It may or may not get a response to the ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Ping request UDP C# PocketPC
    ... I recently set up a UDP connection between a PC and CE device using .NET. ... Since I can't catch any exception with the ... > Socket class, which verify every x seconds if the server is available. ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: SetSockOpt with SO_REUSEADDR parameter
    ... So I create multiple UDP sockets with the same port to send data. ... happening is that you are throwing away the old socket and replacing it with the new ... When the second client is connecting to server, I still get the error code ...
    (microsoft.public.vc.mfc)
  • Re: Socket connect vs. bind? What is the difference
    ... Actually, if you're doing UDP Multicast, you don't need to connect. ... to call Connect to establish a TCP connection to the remote IPEndPoint. ... is connectionless, so it isn't even necessary to establish a connection to ... It can be set with an overload of the Socket constructor. ...
    (microsoft.public.dotnet.languages.csharp)