networkstream.read

  • Thread starter Thread starter Steve
  • Start date Start date
S

Steve

I'm working on a program that talks to the Yahoo chat servers. But I have
run into a small problem and I'm not sure what to do next. After I
successfully log into yahoo and receive my cookies I think login to their
chat servers. It's at this point I am having the problem. When the following
code executes:

networkstream.Read(bytes, 0, CInt(tcpClient2.ReceiveBufferSize))

Dim returndata As String = Encoding.ASCII.GetString(bytes)

txtReturndata.Text = txtReturndata.Text & returndata


returndata = "YCHT

There is no closing quote either which I find odd since return data is
clearly a string. I believe that there is some character or something being
received after YCHT that is causing the Encoding.ASCII.GetString to choke.
Any suggestions for a method that might work better? Thanks in advance.
 
I think the problem is that the buffer is too small, either on your side or
on the sender's side. You need to increase the buffer and read from the
stream until the stream is empty. The stream probably still contains more
response from the sender. Set it on a loop:

Do
BytesRead = stream.Read(data, 0, data.Length)
TotalBytes += BytesRead
TotalData = [String].Concat(TotalData,
System.Text.Encoding.ASCII.GetString(data, 0, BytesRead))
Loop While stream.DataAvailable

Good luck.
 
Back
Top