Reading data from a network stream
- From: "Swami" <Swami@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 12 Aug 2005 12:04:04 -0700
When I try to read data using the System.Text.ASCIIEncoding.GetString method,
data is not read properly...it seems like the carriage returns and some other
characters are not being interpreted properly. The fiel sI amexpecting in
the stream are pure text files that are supposed to be opened in notepad.
Can some one tell me if there is anythign I am doign wrong? I'll paste the
code snippet below:
Private Sub ReceiveCallBack(ByVal ar As IAsyncResult)
Try
sb = CType(ar.AsyncState, SocketAndBuffer)
numbytes = sb.Socket.EndReceive(ar)
If numbytes > 0 Then
'-- Convert the buffer to a string
receivedData = receivedData & ASCII.GetString(sb.Buffer, 0,
sb.Buffer.GetLength(0))
While receivedData.IndexOf(idxFileFooter) <> -1
ProcessData(receivedData)
receivedData = receivedData.Remove(0, length)
End While
'-- Clear the buffer
Array.Clear(sb.Buffer, 0, sb.Buffer.Length)
'-- Receive again
sb.Socket.BeginReceive(sb.Buffer, 0, sb.Buffer.Length,
SocketFlags.None, AddressOf ReceiveCallBack, sb)
End If
Catch ex As Exception
CreateLogFile("Receive Data Error: " & ex.ToString())
If Not sb.Socket Is Nothing Then
sb.Socket.Shutdown(SocketShutdown.Both)
sb.Socket.Close()
End If
End Try
End Sub
Public Class SocketAndBuffer
Public Socket As System.Net.Sockets.Socket
Public Buffer(2000) As Byte
End Class
.
- Follow-Ups:
- Re: Reading data from a network stream
- From: Arkady Frenkel
- Re: Reading data from a network stream
- Prev by Date: Re: 'correct way' to use an I/O thread to emulate old 'blocking hook' behavior?
- Next by Date: Re: Bandwidth detection
- Previous by thread: Problems joining domain
- Next by thread: Re: Reading data from a network stream
- Index(es):
Relevant Pages
|