A
Alex Clark
Hi All,
I'm having some problems reading a network stream. I'm writing a
lightweight POP client to handle a very specific task, but I keep
unexpectedly reaching the end of the datastream when downloading a large-ish
email (about 10K). This happens about 50% of the time when trying to
download a large email from my POP server. I've tried telnet'ing into the
POP server and manually issuing commands, and it works perfectly --- the
entire email is spat out at my telnet client almost instantly every time.
I have a routine (posted below) which loops through the data in the
datastream, appending it to a string. It waits until it receives the
terminator, a "." followed by a CrLf. Unfortunately, it seems to be
"running out of steam" before the end of the message is downloaded.
I'd really appreciate any help anyone can offer on this as it seems very odd
to me that it would work ok about half of the time and then just completely
time out the other half!
Thanks in advance,
Alex Clark
The code in the routine is as follows:
-------------------------------------------------------
Private Function WaitForResponse(ByVal waitForTerminator As Boolean) As
String
Dim iBR, iTBR As Integer, bBuff(m_Socket.ReceiveBufferSize) As Byte
Dim sResult As String = String.Empty
While Not m_Stream.DataAvailable
Threading.Thread.Sleep(250)
End While
While m_Stream.DataAvailable
iBR = m_Stream.Read(bBuff, 0, bBuff.Length)
iTBR += iBR
sResult &= GetString(bBuff)
If waitForTerminator AndAlso (Not m_Stream.DataAvailable) AndAlso
(Not sResult.EndsWith("." & ControlChars.CrLf)) Then
If (m_Socket.Client.Poll(5000000, SelectMode.SelectRead) =
False) Then
Stop ' Timed out waiting for the end of the message
End If
End If
End While
Return sResult
End Function
-------------------------------------------------------
I'm having some problems reading a network stream. I'm writing a
lightweight POP client to handle a very specific task, but I keep
unexpectedly reaching the end of the datastream when downloading a large-ish
email (about 10K). This happens about 50% of the time when trying to
download a large email from my POP server. I've tried telnet'ing into the
POP server and manually issuing commands, and it works perfectly --- the
entire email is spat out at my telnet client almost instantly every time.
I have a routine (posted below) which loops through the data in the
datastream, appending it to a string. It waits until it receives the
terminator, a "." followed by a CrLf. Unfortunately, it seems to be
"running out of steam" before the end of the message is downloaded.
I'd really appreciate any help anyone can offer on this as it seems very odd
to me that it would work ok about half of the time and then just completely
time out the other half!
Thanks in advance,
Alex Clark
The code in the routine is as follows:
-------------------------------------------------------
Private Function WaitForResponse(ByVal waitForTerminator As Boolean) As
String
Dim iBR, iTBR As Integer, bBuff(m_Socket.ReceiveBufferSize) As Byte
Dim sResult As String = String.Empty
While Not m_Stream.DataAvailable
Threading.Thread.Sleep(250)
End While
While m_Stream.DataAvailable
iBR = m_Stream.Read(bBuff, 0, bBuff.Length)
iTBR += iBR
sResult &= GetString(bBuff)
If waitForTerminator AndAlso (Not m_Stream.DataAvailable) AndAlso
(Not sResult.EndsWith("." & ControlChars.CrLf)) Then
If (m_Socket.Client.Poll(5000000, SelectMode.SelectRead) =
False) Then
Stop ' Timed out waiting for the end of the message
End If
End If
End While
Return sResult
End Function
-------------------------------------------------------