Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

TServerSocket

Posted on 1997-11-02
8
Medium Priority
?
338 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 1

Accepted Solution

by:
ergates earned 800 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

636 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