I am writing a program in VB.net that is connecting to a server, sending a byte array to the server and then receives a byte array as an answer then needs to receive a continuous stream of bits from the server.
The Sent Bit Array is 84 bytes and should be the same the first time it is received from the server and vary in size every time the server sends it back after that.
the start and the end of the message will always be the same but the size of the bit array sent will vary.
My issue is that I can write the bits to the server but I am not able to receive any of the follow-on bits that are broadcast.
Any suggestions
Public Sub connect(TcpClient As TcpClient)
Dim NetworkStream As NetworkStream = TcpClient.GetStream()
If networkStream.CanWrite And networkStream.CanRead Then
' Do a simple write.
Dim sendBytes As [Byte]() = IO.File.ReadAllBytes(startupFile)
networkStream.Write(sendBytes, 0, sendBytes.Length)
' Read the NetworkStream into a byte buffer.
Dim bytes(1024) As Byte
NetworkStream.Read(bytes, 0, bytes.Length)
' Output the data received from the host to the console.
Dim returndata As String = Encoding.ASCII.GetString(bytes)
Dim fileWrite As New IO.StreamWriter(writeFile)
fileWrite.Write(returndata)
fileWrite.Close()
Else
If Not networkStream.CanRead Then
Console.WriteLine("cannot not write data to this stream")
TcpClient.Close()
Else
If Not networkStream.CanWrite Then
Console.WriteLine("cannot read data from this stream")
TcpClient.Close()
End If
End If
End If
End Sub