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 43845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T15:33:33+00:00 2026-05-10T15:33:33+00:00

In VB.net I’m using the TcpClient to retrieve a string of data. I’m constantly

  • 0

In VB.net I’m using the TcpClient to retrieve a string of data. I’m constantly checking the .Connected property to verify if the client is connected but even if the client disconnects this still returns true. What can I use as a workaround for this?

This is a stripped down version of my current code:

Dim client as TcpClient = Nothing client = listener.AcceptTcpClient do while client.connected = true    dim stream as networkStream = client.GetStream()    dim bytes(1024) as byte    dim numCharRead as integer = stream.Read(bytes,0,bytes.length)    dim strRead as string = System.Text.Encoding.ASCII.GetString(bytes,0,i) loop 

I would have figured at least the GetStream() call would throw an exception if the client was disconnected but I’ve closed the other app and it still doesn’t…

Thanks.

EDIT Polling the Client.Available was suggested but that doesn’t solve the issue. If the client is not ‘acutally’ connected available just returns 0.

The key is that I’m trying to allow the connection to stay open and allow me to receive data multiple times over the same socket connection.

  • 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. 2026-05-10T15:33:34+00:00Added an answer on May 10, 2026 at 3:33 pm

    When NetworkStream.Read returns 0, then the connection has been closed. Reference:

    If no data is available for reading, the NetworkStream.Read method will block until data is available. To avoid blocking, you can use the DataAvailable property to determine if data is queued in the incoming network buffer for reading. If DataAvailable returns true, the Read operation will complete immediately. The Read operation will read as much data as is available, up to the number of bytes specified by the size parameter. If the remote host shuts down the connection, and all available data has been received, the Read method will complete immediately and return zero bytes.

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

Sidebar

Ask A Question

Stats

  • Questions 67k
  • Answers 67k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer The ToolBar class defines a Style that makes Buttons look… May 11, 2026 at 11:59 am
  • added an answer Well, you could start a new cmd.exe process and use… May 11, 2026 at 11:59 am
  • added an answer DataSets and DataTables are often more verbose and have some… May 11, 2026 at 11:59 am

Related Questions

In VB.net I'm using the TcpClient to retrieve a string of data. I'm constantly
In VB.NET I'm drawing an ellipse using some code like this. aPen = New
using the Code Snippet for sending email in VB.Net I have successfully sent an
I want to extend the basic ControlCollection in VB.NET so I can just add
I'm writing a small application in VB.NET and I would like some of the
I'm working on a small project in VB.Net where I get a input from
I'm developing a Desktop Search Engine in VB.NET and I'm looking for a powerful,
In my VB.net project I created a custom cursor (Window.cur). How can I assign
I have inherited a class in vb.net and when I create the object, I
In VB.NET (or C#) how can I determine programmatically if a public variable in

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.