Results 1 to 4 of 4

Thread: Sockets Get Stream .net

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2001
    Location
    Pennsylvania
    Posts
    133

    Sockets Get Stream .net

    I have an appliction which is receiving inbound xml which it processes and writes to a database.

    I am having a problem when receiving a large stream. In winsock api I would wait until the whole message was received and parse the streams together to form the file. When I try that here, I do not get the whole file.

    Here is an example of the code.
    VB Code:
    1. Do
    2.                     Dim InBuff(200000) As Byte
    3.                     Client.GetStream().Read(InBuff, 0, InBuff.Length)
    4.                     txtLog.Text = txtLog.Text & vbCrLf & "[" & Now & "] >Processing incoming request."
    5.                     Application.DoEvents()
    6.                     temp = temp & System.Text.Encoding.Default.GetString(InBuff)
    7.                     temp = Trim(temp)
    8.  Loop Until Client.GetStream.DataAvailable = False


    Sometimes I get the whole file on the first run. Could I get some he

  2. #2
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    This should work. If you need me to convert it to VB.NET, let me know...

    Code:
    MemoryStream m = new MemoryStream();
    int iRead;
    byte[] bytes = new byte[4096];
    
    while((iRead = ns.Read(bytes, 0, bytes.Length)) > 0)
    {
        m.Write(bytes, 0, iRead);
    }
    
    string output = System.Text.ASCIIEncoding.ASCII.GetString(m.ToArray());

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2001
    Location
    Pennsylvania
    Posts
    133

    Reply

    Actually, I am using the TcpClient. If I say m.write it will attempt to write it back to the TCPServer I have written or am I wrong on this?

  4. #4
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    MemoryStream just acts as a temporty backing store (memory) for data. The code I posted can be substitued with your do loop..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width