Hi folks,
I am writing a small network application that uses TCP sockets. My
application is the accepts connections via the AcceptConnectio n 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.Sock et object does not seem to
solve the problem. Thank you!
Jason 2 2247
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_m e_not.fastpicsy stems.com> escribió en el
mensaje news:Oy******** ******@TK2MSFTN GP10.phx.gbl... Hi folks,
I am writing a small network application that uses TCP sockets. My application is the accepts connections via the AcceptConnectio n 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.Sock et object does not seem to solve the problem. Thank you!
Jason
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,
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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>
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.settimeout(5.0)
|
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);
|
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 point.
System.Net.IPAddress IPAddress = System.Net.IPAddress.Parse(strPrtrIPAddr);
System.Net.IPEndPoint IPEndPoint = new System.Net.IPEndPoint(IPAddress,
|
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 incoming connection,the relative code snipprt as following::
private IPAddress myIP=IPAddress.Parse("127.0.0.1");
private IPEndPoint myServer;
private Socket socket;
private Socket accSocket;
private System.Windows.Forms.Button button2;...
|
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 as I find appropriate.
I am using the socket asynchronously by calling the BeingSend and
BeginReceive calls. I would like to be able to call shutdown and close
asynchronously if possible.
| |
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.
|
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 mechanisms.
I use a non-blocking approach for this, using the call to 'poll' to
support the async mechanism - rather than the 'begin' and 'end'
functions. I already found that connecting doesn't set the
"isconnected" variable correctly...
|
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 windows and linux.
so I guess there is a problem with makefile().
# Echo server program
|
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 supposed to do the following:
monitor ALL INCOMING TCP traffic on the local computer, and save certain parts of it as files - not log files though, but actual files that are sent to the computer as part of http or ftp. Basically if a user browse a page...
|
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': illegal use of this type as an expression *
* C:\..\..\..\include\winsock2.h: see declaration of 'SOCKET' *
*--------------------------------------------------------------*
What i wrote in my program is like this..:
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |