473,405 Members | 2,187 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Problem determining when a remote host closes a socket. using TcpClient

I am using the TcpClient to connect to a web site. I then open a
NetworkStream and read the contents that are being sent back. The
problem is that I have no idea when the remote host is finished
sending data. It is sending a web page but it doesn't use the
Content-Length header to indicate the size.

While I can use the DataAvailable property, it is well known that you
cannot rely on this to know when no more data is available.

What I really want is to know when the host has closed the underlying
socket. I have a loop where I continually read from the host when the
DataAvailable is true. At some point however, I was hoping that the
remote host would close the socket and I would capture an exception
indicating a closed socket. But my try...catch never gets an exception
and I remain forever in the loop.

I can't be 100% certain that the remote host is closing the
connection, but if I have read all of the data, why wouldn't it?

How can I get my code to capture an exception indicating a closed
socket? Maybe TcpClient is the wrong way to go?

Thanks,
Johann
Nov 16 '05 #1
0 1666

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Nick Zdunic | last post by:
Ok - something for socket jockeys I have a .NET application using the TcpClient class from System.Net.Sockets I use this to connect to an IP address/Socket on the other side of Australia. ...
2
by: Theo | last post by:
Hi, I am using a tcpclient and a tcplistener to send and receive packets. The client sends a packet and the listener replies with another one. I can send 2 packets and get an answer from the...
3
by: David | last post by:
Hi, Ive been trying to work this out for the past 2 days now and im not getting anywhere fast. The problem i have is that i am using Asynchronous sockets to create a Socket Client library....
3
by: minying | last post by:
Hi everyone! I am experiencing a problem when trying to establish a TCP connection between a program running locally and another program running on the Pocket PC emulator provided by the...
2
by: Droopy | last post by:
Hi, I try to implement a reusable socket class to send and receive data. It seems to work but I have 2 problems : 1) I rely on Socket.Available to detect that the connection is closed (no...
1
by: Mr. Beck | last post by:
Hello, Please Help..... I have been working with some tcp/ip socket communication within a C# program recently. Basicly, I have a program (myProblemProgram) that has a socket connected to...
2
by: jgbid | last post by:
Hi, I'm trying to build an IP Scanner inc c# for a specific port (80) and for specific IP Ranges. For example 24.36.148.1 to 24.36.148.255 My first step was to use TcpClient, but there are...
1
by: xreload | last post by:
Hello ! I have some class for getting html documents : """ Wrapper for Python sockets lib """ import socket import urlparse import random
1
by: Ryan Liu | last post by:
Hi, I have a 100 clients/ one server application, use ugly one thread pre client approach. And both side user sync I/O. I frequently see the error on server side(client side code is same, but...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.