Hi,
Please excuse my choice of wording and/or mixup of terms, I am a dummy when it comes to socket programming. I am trying to connect to a TCP server, write a message and process a response. I use the following code:
Dim tcpClient As Sockets.TcpClient = New TcpClient()
tcpClient.Connect(hostname, 9080)
Dim networkStream As NetworkStream = tcpClient.GetStream()
If networkStream.CanWrite And networkStream.CanRead Then
Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(body)
networkStream.Write(sendBytes, 0, sendBytes.Length)
Dim bytes(tcpClient.ReceiveBufferSize) As Byte
networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))
Dim returndata As String = Encoding.ASCII.GetString(bytes)
End If
I can see the server logs and notice that the server only ever reads from the socket when I stop debugging. It then processes the message and sends a response (which is a bit late as my client is not listening anymore).
It seems the networkStream object needs to be closed first. However, if I do this I can not process any subsequent response. Do I need to 'signal' to the server that I have finished writing? Do I need to use a different model altogether?
All responses or pointers are much appreciated.