networkstream return white space.

  • Thread starter Thread starter Guoqi Zheng
  • Start date Start date
G

Guoqi Zheng

Dear sir,

I am using .NET tcpClient to connect to remote POP server. When I get the
string from server response, the string always contains many white space.

I think the ReceiveBufferSize is always too big, it seems to me that server
always response with a fix buffer size, but send the response stream in 3
times. I tried to get rid of those white space by trim or regex, but not any
lucky,

any one understand what I am taking about?

Any help will be appreciated!!! Please see my code example below.

Do While (qqNetworkStream.DataAvailable)

Dim bytes(qqTcpClient.ReceiveBufferSize) As Byte

qqNetworkStream.Read(bytes, 0, CInt(qqTcpClient.ReceiveBufferSize))

Dim tempString As String = System.Text.Encoding.UTF8.GetString(bytes)

Tmr = Now.TimeOfDay.TotalSeconds - Start

Dim boolTest As Boolean = False

boolTest = Regex.IsMatch(fReturn, "\r\n\.\r\n",
RegexOptions.Singleline)

If boolTest = True Or Tmr > m_TimeOut Then

Exit Do

End If

System.Threading.Thread.Sleep(300)

Loop

Return tempString



--
Kind regards

Guoqi Zheng
guoqi AT meetholland dot com
Http://www.meetholland.com
 
Hi Guoqi Zheng,

NetworkStream.Read returns the number of bytes read, so when you get your string, you want to use only the bytes that were read, not the whole buffer.
Here's a help topic that gives an example http://msdn.microsoft.com/library/default.asp?url=/library/en-
us/cpref/html/frlrfsystemnetsocketsnetworkstreamclassreadtopic.asp

Hope this helps,
Craig VB.Net Team
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top