In VB.net, I use TcpClient to retrieve a data string. I constantly check the .Connected property to check if the client is connected, but even if the client disconnects, it still returns true. What can I use as a workaround for this?
This is a stripped down version of my current code:
Dim client as TcpClient = Nothing client = listener.AcceptTcpClient do while client.connected = true dim stream as networkStream = client.GetStream() dim bytes(1024) as byte dim numCharRead as integer = stream.Read(bytes,0,bytes.length) dim strRead as string = System.Text.Encoding.ASCII.GetString(bytes,0,i) loop
I would suggest that at least a call to GetStream () would throw an exception if the client was disconnected, but I closed another application and it still doesn't ...
Thanks.
EDIT Customer survey. Presumably, but this did not solve the problem. If the client does not have access to "acutally", it simply returns 0.
The key is that I'm trying to allow the connection to remain open and allow me to receive data several times over the same socket connection.
source share