Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 531847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:20:37+00:00 2026-05-13T09:20:37+00:00

It seems the most obvious thing, but I just can’t work out how to

  • 0

It seems the most obvious thing, but I just can’t work out how to get the length of bytes sent over a network using a TCPClient and TCPListener?
This is my code so far:

   'Must listen on correct port- must be same as port client wants to connect on.
    Const portNumber As Integer = 9999
    Dim tcpListener As New TcpListener(IPAddress.Parse("192.168.2.7"), portNumber)

    tcpListener.Start()
    Console.WriteLine("Waiting for connection...")

    'Accept the pending client connection and return 
    'a TcpClient initialized for communication. 
    Dim tcpClient As TcpClient = tcpListener.AcceptTcpClient()
    Console.WriteLine("Connection accepted.")
    ' Get the stream
    Dim networkStream As NetworkStream = tcpClient.GetStream()
    '' Read the stream into a byte array

I need to get the length of the networkstream to set the size of the array of bytes I’m going to read the data into. But the networkStream.length is unsupported and does not work and throws an Notsupportedexception.

The only other way I can think of is to send the size of the data before sending the data, but this seems the long way round.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T09:20:37+00:00Added an answer on May 13, 2026 at 9:20 am

    Not sure what object type you are expecting but this works and you could keep track of the final size, sorry in C# though:

    System.Net.Sockets.NetworkStream nwStream = objTcp.GetStream();
    System.IO.StreamReader stReader = new System.IO.StreamReader(nwStream);
    
    string strTemp = ReadFromBuffer(stReader);
    
    private string ReadFromBuffer(System.IO.StreamReader objReader)
    {
            int intRead=1024;
            System.Text.StringBuilder stbBugger = new StringBuilder();
            char[] chrTempBuffer = new char[1024];
    
            while (intRead == 1024)
            {
                intRead = objReader.Read(chrTempBuffer, 0, 1024);
                stbBugger.Append(chrTempBuffer, 0, intRead);
            }
    
            return stbBugger.ToString();
        }
    

    It all depends on what you are needing to read and what type of stream you use. The method here you could add a count to as well while reading the results if you really needed to.

    Just keep track of the number of char’s read during the operation and you have a size plus the data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This seems like an obvious thing to want to do but I have pulled
I've been looking into CEDET, but it seems that most of its features would
Most of Knockout seems very intuitive. One thing that is strange to me though
Apologies, my question may be incorrect, but CLIENT_LOCALE seems like the current most-likely culprit:
I'm trying to get a threaded process working, but it seems to get more
Seems I want to do the opposite of what most people ask for when
Most times I see people try to use linked lists, it seems to me
This is not as simple as it seems. Most of you are likely thinking
My question may seem a little weird but I am sure most of you
Seems to be a problem that many people have, but all the answers I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.