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...
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.