davros51

I am developing a Pocket PC app which allows the user to take the PDA around a parking lot while entering information on a form and saving. When the Save button is clicked I want to not only save it to the PDA but send the information to a laptop sitting in the user's vehicle. This laptop listens for a connection request. I know how to transmit and receive files using sockets but I need to be able to instantly detect when the PDA has lost the connection with the laptop (losing the signal by putting a building in between the PDA and the laptop, for instance). I want the PDA to inform the user that the signal has been interrupted and keep trying to connect to the laptop before sending the file. As soon as the connection has been re-established the user should be informed so he/she can continue working. The problem is, there is about a 25 to 40 second wait before a disconnect is detected by the program/pda. By this time the user may have tried sending information to the laptop and lost it not knowing that the signal has been dropped. I thought of using a constant ping on another socket but the Ping class is not supported by the compact framework. Any ideas Thanks!!


Re: .NET Compact Framework Need to instantly detect socket disconnect.

Ilya Tumanov

You would probably need to develop your own communication protocol without timeouts and use it instead of TCP/IP.






Re: .NET Compact Framework Need to instantly detect socket disconnect.

davros51

I am relatively new to .NET let alone the CF. Developing my own communication protocol is way above my head. I hope that someone somewhere has had this same problem and can point me in the right direction. Thanks.




Re: .NET Compact Framework Need to instantly detect socket disconnect.

Ilya Tumanov

It¡¯s not an easy task and there¡¯s a good reason TCP uses timeouts.

I would suggest using MSMQ so there¡¯s no need to detect a disconnect. With MSMQ you can send a message regardless of connection status and MSMQ would deliver is as soon as it could even if your application is not running.






Re: .NET Compact Framework Need to instantly detect socket disconnect.

davros51

Thanks! I think this is a good start to solving my problem. I will so some more research and see if it can be incorporated into my project.




Re: .NET Compact Framework Need to instantly detect socket disconnect.

jorgevarona

We've had this problem for some time now. It seems that if you're using a blocking socket in .NET you wont get any indication of a disconnect on the socket until you perform another operation. What you can do is place the socket in a BeginReceive() and have the callback deal with the disconnect. If YOU are not performing any operations on the socket, placing it in a BeginReceive state will have the CallBack code called upon a disconnect from the other end.

// Place the socket in a receiving state
socket.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, out error, RemovePassiveSocketCallback, socket);

// Callback is called upon disconnect
private void RemovePassiveSocketCallback(IAsyncResult result)
{
Socket socket = (Socket)result.AsyncState;
RemoveBadSocket(socket);
}




Re: .NET Compact Framework Need to instantly detect socket disconnect.

dvboom

I'm interested in this technique of putting the socket in a listening state to detect a disconnection.

While the socket is listening, can I still send data out through it Or do I have to stop it from listening, then send, then start it listening again Is TCP full-duplex

Does this detect a disconnect immediately Have you noticed any scenarios where it doesn't detect one