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

  • Home
  • SEARCH
  • 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 6691209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:43:31+00:00 2026-05-26T05:43:31+00:00

I am struggling a lot with this code I am trying to get to

  • 0

I am struggling a lot with this code I am trying to get to work. I have successfully made a connection with the TcpClient object to two separate remote machines and transmitted data to them. Essentially, I’m trying to connect to Machine 1 on port 80 and send a GET request. Once I send the request I want to keep the connection alive so that the software on the other side can send me data when it is ready. How do I keep the connection open and read data in each time it is made available in the stream? I have tried and tried using NetworkStream.Read and BeginRead to no avail. The closest I have come was sleeping my thread every 30 seconds and then doing another GET request which is not needed. Here is the current code I have for reading from the stream. I know I need a loop in here somewhere:

Note: RemoteSocket is my TcpClient object that is connected by this point

Dim serverStream As NetworkStream = RemoteSocket.GetStream()
rqst = "GET /Control/Clip_Forwarding_Stream?CameraName=" & URL_Encode(Name) & " HTTP/1.0" & vbCrLf & vbCrLf
Dim stream As Byte() = Encoding.GetEncoding("Windows-1252").GetBytes(rqst)
serverStream.Write(stream, 0, stream.Length)
Dim inStream(1024) As Byte
Dim recv = serverStream.Read(inStream, 0, inStream.Length)
Dim data = Encoding.GetEncoding("Windows-1252").GetString(inStream, 0, recv)

What I do with data is pass it to this method:

Note: ForwardSocket is my other TcpClient object that is connected by this point

Dim serverStream As NetworkStream = ForwardSocket.GetStream()
Dim stream As Byte() = Encoding.GetEncoding("Windows-1252").GetBytes(data)
serverStream.Write(stream, 0, stream.Length)

Any examples can be in C# or VB as I’m most comfortable with C# just had to write this all in VB.

  • 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-26T05:43:31+00:00Added an answer on May 26, 2026 at 5:43 am

    You need to read within a loop (similar to NoAlias’s answer). But you should not just loop until DataAvailable is false because if, for the sake of arguement you had 4K of data come in, then there is a small pause (network congestion, whatever) and then another 2K of data came in you would loose the end of your data because DataAvailable would have been false in that pause.

    Instead, you need to rely on the higher-level protocol, which in this case is HTTP. HTTP uses a header called Content-Length that will tell you exactly how many bytes will be present in the body. You need to loop until you have received that amount of content (or have reached a timeout value of course, unless you want to wait forever).

    EDIT1

    Upon reading your question again, it looks like you may be fetching data that has no known content length. HTTP supports sending data in chunks using multipart. This isn’t fun to hand-code, you may want to look at using HttpRequest and HttpResponse classes instead to handle this for you. It still makes available to you a stream with your content but deals with HTTP for you.

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

Sidebar

Related Questions

I'm struggling a lot trying to get our build server going. I am currently
I have been struggling a while with this problem and read a lot but
been struggling with an issue now for a day or two. I have an
I'm struggling to find the right terminology here, but if you have jQuery object...
I have taken over a project that has a lot of code that is
I have been struggling with this seeminly easy problem for 48 hours, and I
Hoping someone can help me design this correctly. In my TCP code, I have
I've been struggling for a few days with this problem , learning a lot
I have been struggling for days trying to find the proper way to implement
I have search through google and found that a lot of people is struggling

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.