Hello to all
i opened a socket for receiving data from server.
after that i sending command and the server sending me back a string.
The problem is to receive full string i need to connect minimum 3 times.
For example:
First result hell
second will be o world
The last and the correct one : Hello world
The Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim serverStream As NetworkStream = clientSocket.GetStream()
Dim outStream As Byte() = System.Text.Encoding.ASCII.GetBytes("COMMAND" & vbCrLf)
serverStream.Write(outStream, 0, outStream.Length)
serverStream.Flush()
Dim myReadBuffer(1024) As Byte
Dim numberOfBytesRead As Integer = 0
Dim myCompleteMessage As StringBuilder = New StringBuilder()
Do
numberOfBytesRead = serverStream.Read(myReadBuffer, 0, myReadBuffer.Length)
myCompleteMessage.AppendFormat("{0}", Encoding.ASCII.GetString(myReadBuffer, 0, numberOfBytesRead))
Loop While serverStream.DataAvailable
returndata = myCompleteMessage.ToString()
TextBox1.Text = returndata
End Sub
I tried to make myReadBuffer larger, the same result
the interesting thing is if i putting breaking point on Loop while its doing the job
until the string is not full its not exit the while
Do i need to change the while condition ? or is it the server
Thank you.