Solved

TServerSocket

Posted on 1997-11-02
8
313 Views
Last Modified: 2010-04-04
Is there any event that triggers disconnections of the pc's cable from the hub that connect it to the internet ?

What about a procedure like "IsAlive"?

Thank in advance

Ronit
0
Comment
Question by:ronit051397
  • 3
  • 3
  • 2
8 Comments
 
LVL 1

Accepted Solution

by:
ergates earned 200 total points
Comment Utility
Although the network interface card may be able to detect a hardware disconnection, I know of no interface that would make this info available to an application.

In general at the TCP socket level you can only try doing something and see if it times out.

An "IsAlive" could do a TCP connection or maybe a "ping" to a reliable host on the other side of the connection, e.g an internet router. If you get no response then the connection may be gone.

There is a freeware component on the Delphi Super Page in the file icmp.zip, which has a ping component and some sample code.

Regards,

0
 
LVL 5

Expert Comment

by:julio011597
Comment Utility
Timeouts for socket streams are matter of minutes.

To check for a disconnection of the peer, you will just write to the socket at custom intervals and look for a broken pipe.

Rgds, julio
0
 
LVL 1

Expert Comment

by:ergates
Comment Utility
Although socket timeouts are relatively long, you can always run your own timer, and not rely on the comms. It seems easier to do a connect, rather than find a host you can keep sending data to.

If you want response times down to seconds, I would recommend the ICMP ping method. I noticed an applet on Delphi Super Page which uses the icmp component to give a real time status display of a number of hosts, could be fun!

Regards,


0
 
LVL 5

Author Comment

by:ronit051397
Comment Utility
I wand to use the function "SetSockOpt" and change the "KeepAlive" option to true, do you have an example source ?
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 5

Expert Comment

by:julio011597
Comment Utility
Sorry, but ping is definitely not a choice:
you could ping (or connect, in general) to know if there's anybody on the other side, still you won't know if _your_ program's connection is alive.
In fact, an "IsAlive" does not do a TCP connect or ping.

ronit:
keep in mind that, anycase, a socket would time out in about 15-20 minutes, depending on the OS... are you prepared to wait so long?

I would strongly suggest the Socket FAQ (somewhere on-line): it's an invaluable source of information.

Bye, julio
0
 
LVL 5

Author Comment

by:ronit051397
Comment Utility
Thanks Julio

Do you know how can I use the "SetSockOpt" Function and change the "KeepAlive" flag?
0
 
LVL 1

Expert Comment

by:ergates
Comment Utility
This is the sort of code I use in my socket component:

var
   err : integer;
   optval : integer;
   sock : socket;
begin
   ...
   optval := 1;
   err := setsockopt (sock, SOL_SOCKET, SO_KEEPALIVE, @optval, sizeof(optval));
   if err = SOCKET_ERROR then
      err := WSAGetLastError;
   ...

However, the KEEPALIVE timeout is by default 2 hours (see RFC 1122). I had thought "IsAlive" was a hypothetical procedure, were you referring to a real procedure?

The question you asked was how to detect if a PC was disconnected from the network, not if a particular TCP connection is disconnected. As I said in my original answer, the way to detect if a TCP connection is alive is to send some data and see if you get a response. See RFC 1123 for discussions of how applications such as SMTP should operate timeouts. TCP timeouts are typically 2-4 minutes (RFC 0793). If you can't wait that long you can run your own timer.

I could write a book about how TCP/IP protocols work, but basically it is up to the client application and server to ensure their connection is operating correctly. The underlying layers will not tell you the connection is lost, because they simply don't know.

I rarely need to look at FAQs, I have been writing comms software for 10 years, and I go to the specifications (RFCS, Winsock spec) if I need to look up something.

There is a Winsock FAQ at the Stardust site, http://www.stardust.com/wsresource/wsresrce.html, but it doesn't mention keepalive functions. There is also an FAQ for Unix/C programmers at http://prominence.com/books/net/cd/socket/unix-socket-faq.html.

What is the application you are writing, and why do you need to detect disconnection? Also let me know where you have seen this "IsAlive" function.

Regards,
0
 
LVL 5

Author Comment

by:ronit051397
Comment Utility
Thanks ergates and julio for your answers it was helpfull.

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now