473,325 Members | 2,870 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,325 software developers and data experts.

TCPListener - Client Disconnect

I recently upgraded my application from VB6, and was using the Winsock
control. In VB2005 I am using the TcpListener Class and have managed to get
it working, except for one thing:

Is there a way for the server to detect when a client disconnects (i.e.
closes the program abruptly)? In VB6 the Winsock control had the Close event,
which would fire when the client disconnected.

Some suggest that it can be done by sending a message to the client at
regular intervals (heartbeat) to check for connectivity, but I would rather
not have to do this.

Is there a method for when the client disconnects?

Feb 19 '07 #1
4 7725
"Hiwj" <Hi**@discussions.microsoft.comschrieb
I recently upgraded my application from VB6, and was using the
Winsock control. In VB2005 I am using the TcpListener Class and have
managed to get it working, except for one thing:

Is there a way for the server to detect when a client disconnects
(i.e. closes the program abruptly)? In VB6 the Winsock control had
the Close event, which would fire when the client disconnected.

Some suggest that it can be done by sending a message to the client
at regular intervals (heartbeat) to check for connectivity, but I
would rather not have to do this.

Is there a method for when the client disconnects?


An event? I don't think so. More:

http://groups.google.com/groups/sear...ublic.dotnet.*

Armin

Feb 19 '07 #2
when a client disconnects, the number of bytes sent is 0....for example

private sub BytesReceived(ByVal ar As IAsycResult)

Dim numBytes as integer = ClientSocket.EndReceive(ar

if numBytes = 0

''close connection, client disconnected

....

end sub
in the method where you receive information, create a check like that and
you will be notified when a client disconnects

hope this helps

--
-iwdu15
Feb 19 '07 #3
Ok, but what if the client does not send a constant stream data to the server? - such as in the case of a client command prompt? How then can you tell when the client disconnects?

EggHeadCafe.com - .NET Developer Portal of Choice
http://www.eggheadcafe.com
Mar 12 '07 #4
since its a TCP connection, you dont have to worry about a constant stream of
bytes. whenever the connection is broken, the Received method will be called
with the number of bytes being 0. thats how you can tell if the client
disconnects
--
-iwdu15
Mar 12 '07 #5

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

Similar topics

1
by: zZ | last post by:
Hi All, I'm building a TCPListener as the server to accept TCPClient connections, using TCPListener.AcceptTcpClient. I'd like to retrieve client's IP after connected, but found no way to do...
1
by: Reshma Prabhu | last post by:
Hello, I have created a client-server application using TcpListener and TcpClient. But the TcpListener stops listening after some amount of time if the client does not send any data. What is...
4
by: Rob White | last post by:
OK, so I have a TcpListener that is waiting for sockets, this piece of code: IPAddress localAddress = Dns.GetHostByName(Dns.GetHostName()).AddressList; IPEndPoint localEP = new...
2
by: MuZZy | last post by:
Hi, The app i develop supose to have a remote control/reporting feature, so that if a client connects to it, he can obtain information about application state and to send some commands. I...
2
by: Dave Coate | last post by:
Hi, I am working on a client-server app. I can get two applications to talk to each other on the same machine using 127.0.0.1, but as soon as I try it using a computer name or actual IP address...
2
by: Terry Olsen | last post by:
Hoping someone can help me here. I've got this code written, and it works fine for the first connection. But if I connect another client (while the first is still connected), I get connected but...
5
by: Jerry Spence1 | last post by:
I have the following example of a tcpListener. I have a device external to my PC which is sending a TCP request on port 10002. This is working OK as I have a network sniffer on my PC and can see...
3
by: Bjørn Eliasen | last post by:
Hi, I have an application running on all pc's in our company. Basically it is a TCPListener awaiting for sockets to connect and on connection performs the required tasks. The app works fine, but...
7
by: ethangk | last post by:
Hey, Im making an app in c#.net, i set up the listener, when it hits the while, it crashes. The code is straight from the ms example, modified a bit for a form instead of command line. Heres the...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.