Reading data from a network stream

Tech-Archive recommends: Speed Up your PC by fixing your registry



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: Data Validation for TextBoxes
    ... that method will not prevent users from pasting in "invalid" characters. ... Private Sub TextBox1_MouseDown(ByVal Button As Integer, ... Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) ... Also, how can I do it for many TextBoxes, ...
    (microsoft.public.excel.programming)
  • Error in VBA code
    ... I've been using the code below to enter a set of numbers & alpha characters ... Dim s As String ... Static bExit As Boolean ... Private Sub txtInvClaim_Exit ...
    (microsoft.public.excel.programming)
  • Re: color conversion
    ... Private Sub Command1_Click ... characters in Text1 in a single step. ... MsgBox ("Invalid Characters in the Hex field!") ...
    (microsoft.public.vb.general.discussion)
  • Re: Combo Box selection populates text box
    ... Put the phase value strings into the first field, ... of carriage return and line feed characters) by pressing Ctrl+Enter when ... Private Sub Phase_AfterUpdate ... My attempt was to use an external word doc for these long phase details. ...
    (microsoft.public.access.forms)
  • Re: automatically adding 1 to a recordset
    ... does not know that you've established an event procedure for the form's ... One of the errors was actually the "Private Sub ... I have slightly changed the code to test if the "SENE CASE #" control ... or with # characters unless you enclose the name in characters. ...
    (microsoft.public.access.forms)