locked
.NET socket networkstream.read strange results. RRS feed

  • Question

  • User-1320437544 posted

    Hi guys,

     

    I am doing client/server socket based project and currently I am having some troubles with the recieved result.

    What I mean ... this is part of the client which is recieving

     

     tcpClient.Connect(address, Port)

    Dim bytes(tcpClient.ReceiveBufferSize) As Byte

    Dim networkstream As NetworkStream = tcpClient.GetStream

    networkstream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))

    Dim file As String = System.Text.Encoding.ASCII.GetString(bytes)

     

    Where file is just a simple file name send from the server. What I recieve is for example: test.txt%00%00%00%00%00%00%00%00 etc. The server and the client are using the same encoding ASCII. Any ideas are welcome.

    Thank you.

    Sunday, July 22, 2012 12:29 PM

Answers

  • User-1320437544 posted

    Never mind I found it.

    For those in the "same boat" if your buffer size is bigger than the data you are recieving than it will be filled out with null bytes the rest of the buffer. All you have to do is to get only the useful data of the buffer or to resize the buffer acording to the size of the data you are recieving.

     

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, July 22, 2012 12:59 PM