473,473 Members | 2,170 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Determine if TcpClient is still connected to socket server

Hi folks,

I use a TcpClient object to connect to a local (asynchron) socket server.
Once the connection is established, I ask every second if there is a new
entry in the socket queue.
If the connection was established successfully at the beginning and ends for
some reason after a certain time, I have to reconnect to the socket server.

So, what I need therefore is a TcpClient attribute such as "Connected" that
returns true if connection is still available, otherwise false.
I read some examples on the internet with TcpClients where an attribute
"Connected" is used, but it does not belong to the TcpClient Class (maybee
it has been removed in the last .NET framework).

There is also an attribute "Active" that only tells you if the connection
has been established at the beginning, but does not track the connection
state.

How can I solve this problem?

Thanks for any help!!

Best regards,
David
Nov 17 '05 #1
1 6735
To do this you should need to create a derivative of the TcpClient
class and expose the Client.Connected property. (The Client (socket)
is a public property in the .NET Framework 2.0 so this is only required
for 1.1 and bellow.)

public class MyTcpClient : TcpClient {

public MyTcpClient(Socket Client):base() {
this.Client=Client;

}

public Socket GetClient
{
get
{
return this.Client;
}
}
public bool Connected{
get {
return this.Client.Connected;
}
}

}
}

--Michael Davidov

Nov 17 '05 #2

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

Similar topics

3
by: Daniel | last post by:
TcpClient close() method socket leak when i use TcpClient to open a connection, send data and close the TcpClient with myTcpClientInstance.Close(); it takes 60 seconds for the actual socket on...
1
by: Patrick | last post by:
Hi... I've written a small client, that uses the TCPClient for connecting to a server and receives data from the server. When the connection is idle, after 5 minutes I get disconnected from the...
1
by: crashed | last post by:
Hi, I am using C# in .NET 2.0 and im trying to read a stream from a socket. The code works on the first attempt but fails on subsequent attempts. It is in a multithreaded application. It seems...
3
by: Ryan Liu | last post by:
Hi, I use Server: Use an endless thread to lisiten to clients requests: while(true) { TcpClient client = myListener.AcceptTcpClient();
7
by: semedao | last post by:
Hi all, I view many posts about this issue , the connected property does not tell us the current status of the socket. based on couple of suggestions of msdn , and some article here , I try to...
7
by: illegal.prime | last post by:
Hi all, I've got a client/server application and just wanted to ensure that this is expected behavior. I recently set the following configuration in Visual Studio: Debug->Exceptions->Break Into...
0
by: John Mott | last post by:
Hello, I'm not really sure if this is the best place but I couldn't find a TCP specific newsgroup. It appears that the DataAvailable property of the TCPClient is just a test for whether data...
6
by: Bjoern Schliessmann | last post by:
Hello, I'm currently trying to implement a simulation program with Kamaelia and need a reliable TCP connection to a data server. From Twisted, I know that a method is called if the connection...
10
by: Jan Vinten | last post by:
Hi all, I got into some trouble trying to bind to a specific IP address. Code: Private mobjClient As TcpClient mobjClient = New TcpClient(IPAddress.Parse("10.16.104.87").ToString, 8892)
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.