Re: Reading data from a network stream
- From: "Arkady Frenkel" <arkadyf@xxxxxxxxxxxxxxxx>
- Date: Sat, 13 Aug 2005 13:21:16 +0200
Hi!
Just a question : why you need ASCIIEncoding ( maybe that VB demand ) ? If
you send file which include cr,lf you can save data "as is" on receiving
host
Arkady
"Swami" <Swami@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:6B773405-12F5-468B-B947-FB436290EF85@xxxxxxxxxxxxxxxx
> 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: Swami
- Re: Reading data from a network stream
- References:
- Reading data from a network stream
- From: Swami
- Reading data from a network stream
- Prev by Date: Re: Error in send, while using IP_HDRINCL
- Next by Date: Re: Error in send, while using IP_HDRINCL
- Previous by thread: Reading data from a network stream
- Next by thread: Re: Reading data from a network stream
- Index(es):
Relevant Pages
|