davros51

I need a very fast way to detect if a connection has been lost between the PDA and the remote machine. I have built a "heartbeat" between the two machines running in a timer's click event every second using this code...

Code Snippet

Dim serverIP As IPAddress
serverIP = IPAddress.Parse(msIpAddress)

Dim client As New TcpClient

client.Connect(New IPEndPoint(serverIP, SOCKET2))

Dim message1 As String = "<Packet><TemplateID>PROG_CONNECT_100</TemplateID></Packet>"
Dim byteResponse As Byte() = Encoding.ASCII.GetBytes(message1.ToCharArray())

client.GetStream.Write(byteResponse, 0, byteResponse.Length)

Dim netStream As NetworkStream = client.GetStream()
If netStream.DataAvailable Then
Dim bytes(client.ReceiveBufferSize) As Byte
netStream.Read(bytes, 0, CInt(client.ReceiveBufferSize))
Dim returndata As String = Encoding.ASCII.GetString(bytes, 0, client.ReceiveBufferSize)
End If
client.Close()
netStream.Close()

It takes about 35 to 40 seconds for an exception to be thrown allowing me to pop up a message box informing the user that the connection has been lost. Also the other machine responds with a string once data arrives there, but I am not receiving it for some reason. Why does it take so long and is there a way to detect the disconnect within a few seconds and why am I not getting the return string The user is inputting data into the PDA then it is sent to the remote computer. This means he/she may not know in a timely manner that their work is not being sent. Thanks in advance for any advice.




Re: .NET Compact Framework Fast client disconnect possible?

Stephen Hauck

You can register for notification when the connection manager has a change in connection status or poll it to see if it still has a connection.





Re: .NET Compact Framework Fast client disconnect possible?

davros51

Could you please be a little more specific What is a connection manager and what do you mean by "poll it to see if it still has a connection" I am running this code on a timer click event which tries to connect every one second. Is this what you mean Thanks!




Re: .NET Compact Framework Fast client disconnect possible?

Stephen Hauck

You need to do some research on MSDN about the connection manager.

http://www.google.com/search q=Connection+Manager+pocket+pc+MSDN&hl=en&safe=active

By poll I mean call a function in the connection manager API that will report the status of the connection.





Re: .NET Compact Framework Fast client disconnect possible?

alex2233

have a look at www.dotnetremoting.com , might be helpful