I’m sending a string across the network and everytime I check the side receiving the string, it always tells me that the length of the string received is 8193. But when I try to assign a value before it is displayed in the MsgBox, it returns the correct value. I tried trimming the string using String.Trim(Chr(10))*, String.Trim(Chr(13)), String.Trim(ChrW(8193)) but to no avail.
Does anybody have any idea about this?
Here’s my code for the receiving side.
Private Sub ChatConnectionTimer_Tick(sender As Object, e As System.EventArgs) Handles ChatConnectionTimer.Tick
Try
Dim ConnectionStatus As String = String.Empty
If CBool(chatClientSocket.Available) Then
chatNetworkStream = chatClientSocket.GetStream()
Dim ByteData(chatClientSocket.ReceiveBufferSize) As Byte
chatNetworkStream.Read(ByteData, 0, CInt(chatClientSocket.ReceiveBufferSize))
ConnectionStatus = Encoding.ASCII.GetString(ByteData)
MsgBox(ConnectionStatus.Length()) 'This part always return 8193
If ConnectionStatus.Contains("Server is disconnected.") Then
DisconnectChat()
End If
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Try
End Sub
Your ByteData buffer is always the size of ReceiveBufferSize. What you want to do is check how much .Read returned and use that as the length of the returned message.