Solved

TServerSocket

Posted on 1997-11-02
8
314 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
ID: 1349339
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
ID: 1349340
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
ID: 1349341
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
ID: 1349342
I wand to use the function "SetSockOpt" and change the "KeepAlive" option to true, do you have an example source ?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 5

Expert Comment

by:julio011597
ID: 1349343
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
ID: 1349344
Thanks Julio

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

Expert Comment

by:ergates
ID: 1349345
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
ID: 1349346
Thanks ergates and julio for your answers it was helpfull.

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

932 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

8 Experts available now in Live!

Get 1:1 Help Now