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

Related Questions

.NET's Ajax helper has the LoadingElementId: String property, gets and sets the ID of
.NET developers out there! Need your opinion here! I am now using Visual Assist
.NET has a lot of complex data structures. Unfortunately, some of them are quite
.NET balanced group regexes make my head explode. I've got this string i'm trying
.NET allows to extend XSLT by using the so called extension object. Very handy
.NET newbie alert Using Visual C# 2008 Express Edition I have accidentally created a
.NET I have a web service, one of the data members of a message
.NET's HttpSessionState using an InProc store seems to treat session variable key values as
.Net 3.5 doesn't support tuples. Too bad, But not sure whether the future version
NET app, where I allow Users to map a location using google maps and

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.