Re: Reading data from a network stream

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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


.



Relevant Pages

  • Re: Reading data from a network stream
    ... Arkady ... >>> Private Sub ReceiveCallBack ... >>> Public Class SocketAndBuffer ...
    (microsoft.public.win32.programmer.networks)
  • Re: Need help opening ADO recordset.
    ... and I have been receiving an error message like this: ... A problem occured while Microsoft Access was communicating with the ... Private Sub PutHHIDIntblPeople() ...
    (microsoft.public.access.modulesdaovba)
  • Re: Date stamp on exit
    ... page (page is called "Receiving Testing")and the other ... >'exiting' in your post... ... >private sub kitreturned_afterupdate ... >> I would like to set up a Macro, if possible, that fills ...
    (microsoft.public.access.formscoding)
  • Find Record Question
    ... Record Event for my form which is attached to a table. ... keep receiving this error when I try to use it. ... Private Sub Command1_Click ... DoCmd.OpenForm "frmMain", acNormal,,, acFormAdd ...
    (microsoft.public.access.formscoding)
  • Re: .NET NEWBIE - EASY QUESTION
    ... Private Sub LoginBtn_Click(ByVal sender As System.Object, ... > I have been programming in ASP for years and am making the move to .NET ... against and i am receiving the following error message. ...
    (microsoft.public.dotnet.framework.aspnet)