We help IT Professionals succeed at work.
Get Started

Get the actual data length read from network stream

RadhaKrishnaKiJaya
on
167 Views
Last Modified: 2015-06-23
Hi Experts,

I am reading data from a RFID reader using network stream. But the length of the data is always 8193. What can I do to get the actual length.
Thanks in advance.

Dim tcpClient As New TcpClient("192.145.1.80", "10001")
             Dim netStream As NetworkStream = TcpClient.GetStream()
             If netStream.CanRead Then
                 ' Reads the NetworkStream into a byte buffer.
                 Dim bytes(TcpClient.ReceiveBufferSize) As Byte
                 ' Read can return anything from 0 to numBytesToRead.  
                 ' This method blocks until at least one byte is read.
                 netStream.Read(bytes, 0, CInt(TcpClient.ReceiveBufferSize))

                 ' Returns the data received from the host to the console.
                Dim ReturnData As String = Encoding.ASCII.GetString(bytes)
                 TextBox1.Text = ReturnData  'Length is always 8193
                RaiseEvent TCPDataIn(ReturnData)
             Else
                 Console.WriteLine("You cannot read data from this stream.")
                 TcpClient.Close()
                 ' Closing the tcpClient instance does not close the network stream.
                 netStream.Close()
                 Return
             End If
Comment
Watch Question
Commented:
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE