473,322 Members | 1,806 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,322 software developers and data experts.

Socket problem

Hi folks,

I am writing a small network application that uses TCP sockets. My
application is the accepts connections via the AcceptConnection function
of a server socket and creates a client socket from it. My question is,
if someone disconnects from my server, how can I detect this? Checking
the Connected property of the System.Net.Socket object does not seem to
solve the problem. Thank you!

Jason

Nov 16 '05 #1
2 2217
Hi there...

The Connected property will return the latest known state of the Socket.
There's no way the server detects a client has gone offline... unless you
program it. A couple of months ago I had to develop this app (based on
TCP/IP) and I had the same question as you do. My solution was to implement
some sort of "keep alive" message send from the server to the client in a
time based frequency (it's a parameter in my app's config file). I suppose
that you had to define the protocol that is gonna be used throughout your
application, well consider having this "pinging" message. It's worked
excellent to me.

As a matter of fact, if you issue the netstat command at the prompt having
the client disconnected you still see "the connection" it's a funny thing
but it's true. Have a nice day.

Hope this might help you,

Regards,
--
Angel J. Hernández M.
MCSD

"Jason Hurder" <jhurder@spam_me_not.fastpicsystems.com> escribió en el
mensaje news:Oy**************@TK2MSFTNGP10.phx.gbl...
Hi folks,

I am writing a small network application that uses TCP sockets. My
application is the accepts connections via the AcceptConnection function
of a server socket and creates a client socket from it. My question is, if
someone disconnects from my server, how can I detect this? Checking the
Connected property of the System.Net.Socket object does not seem to solve
the problem. Thank you!

Jason

Nov 16 '05 #2
Hi Angel,

I have seen this behavior after disconnecting the client and using
"netstat -aon" (usually the state will be TIME_WAIT or FIN_WAIT_2 or
CLOSE_WAIT). I'm not really sure what these states are for other than to
alert the OS that those ports can't be used just yet (read that
somewhere on MS's site). I wonder how chat clients do it, they know when
a user logs out.

I guess I could just send a ping message to the client to see if the
client disconnected or not, though it seems to me that this
functionality should already be a part of the API.

Thank you for your help,

Jason
Angel J. Hernández wrote:
Hi there...

The Connected property will return the latest known state of the Socket.
There's no way the server detects a client has gone offline... unless you
program it. A couple of months ago I had to develop this app (based on
TCP/IP) and I had the same question as you do. My solution was to implement
some sort of "keep alive" message send from the server to the client in a
time based frequency (it's a parameter in my app's config file). I suppose
that you had to define the protocol that is gonna be used throughout your
application, well consider having this "pinging" message. It's worked
excellent to me.

As a matter of fact, if you issue the netstat command at the prompt having
the client disconnected you still see "the connection" it's a funny thing
but it's true. Have a nice day.

Hope this might help you,

Regards,


Nov 16 '05 #3

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

Similar topics

3
by: Thomas Hervé | last post by:
My problem is not really python specific but as I do my implementation in python I hope someone here can help me. I have two programs that talk through a socket. Here is the code : <server>...
4
by: Bryan Olson | last post by:
Here's the problem: Suppose we use: import socket f = some_socket.makefile() Then: f.read() is efficient, but verbose, and incorrect (or at least does not play will with others);
4
by: faktujaa | last post by:
Hi, I am having some problem with callback used in socket implementation. private static void Connect(string strPrtrIPAddr, int intPrtrPort, ref Socket rsocClient) { try { // Create remote end...
4
by: zbcong | last post by:
Hello: I write a multithread c# socket server,it is a winform application,there is a richtextbox control and button,when the button is click,the server begin to listen the socket port,waiting for a...
4
by: Chris Tanger | last post by:
Context: C# System.Net.Sockets Socket created with constructor prarmeters Internetwork, Stream and TCP everything else is left at the default parameters and options except linger may be changed...
4
by: Sa¹o Zagoranski | last post by:
Hi! I'm writing a simple 3D First person shooter game. It is a multiplayer game, where all the players connect to one server.
11
by: atlaste | last post by:
Hi, In an attempt to create a full-blown webcrawler I've found myself writing a wrapper around the Socket class in an attempt to make it completely async, supporting timeouts and some scheduling...
6
by: ahlongxp | last post by:
socket.makefile() may lose data when "connection reset by peer". and socket.recv() will never lose the data. change the "1" to "0" in the client code to see the difference. confirmed on both...
0
by: george585 | last post by:
Hello! I am new to network programming, and understand just basics. Using some sample code, and having read documentation, I managed to create a simple app in C# and VB.NET. The application is...
16
by: =?iso-8859-1?q?|-|e|=5F|=5F_B0=DD?= | last post by:
hi all! I got a problem. I declared a SOCKET var in my C program but when i compiled the program it displayed like *--------------------------------------------------------------* *'SOCKET':...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
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: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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...

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.