Board index » delphi » check an in-network ip

check an in-network ip


2004-03-04 02:19:51 PM
delphi201
Hi,
In my chat app there is an 'address book' with nicks and corresponding ip
addresses of participating users.
When i try to conect to a user whs computer is up but chat programm is not
running, i get 'Socket error' on my side - my chat client can not connect to
their chat server, obviousely. And that is fine, that is how i check if
another user is 'online' or 'offline', meaning that either his chat app is
up or not.
BUT!... If that computer is down, so no such ip exists in the network at
that time, and i try to connect, my app is freezing completely, w/o giving
any errors or exceptions..
It just stops on the line:
TcpClient.Connect;
and that is it... The same effect as if i unplug the network cable from my
computer and then try to access any shared resource... freeeezzzinggg......
Any suggestions on how to check if computer is up and if remote chat server
is up?
Is there a way to kinda ping a remote ip on a certain port?
Thank you
Andrey
 
 

Re:check an in-network ip

MuZZy writes:
Quote
Any suggestions on how to check if computer is up and if remote chat
server is up?
Is there a way to kinda ping a remote ip on a certain port?
Why don't you traditionally ping the computer and if it is up try to connect
to the chat port?
--
Ben
 

Re:check an in-network ip

Quote

TcpClient.Connect;

and that is it... The same effect as if i unplug the network cable from my
computer and then try to access any shared resource...
freeeezzzinggg......

Run your client in a thread. Instant anti-freeze.
Rgds,
Martin
 

Re:check an in-network ip

"Ben Hochstrasser" <bhoc@tiscali123^H^H^H.ch>writes
Quote
MuZZy writes:

>Any suggestions on how to check if computer is up and if remote chat
>server is up?
>Is there a way to kinda ping a remote ip on a certain port?

Why don't you traditionally ping the computer and if it is up try to
connect
to the chat port?

Ben, here is a situation: there is a listeninig chat server somewhere in the
network under a router where they have port forwarding for that computer. I
try to send a message from outside the network, so i use router's ip
address.
It will ping, router is always up. But how do i know if that computer behind
the router is up?
And again, if i connect to a 'dead' computer, my compuer is freezing.
So i need somehow to find out is 'ip+port' is active and listening...
Andrey
 

Re:check an in-network ip

"Martin James" <XXXX@XXXXX.COM>writes
Quote
>
>TcpClient.Connect;
>
>and that is it... The same effect as if i unplug the network cable from
my
>computer and then try to access any shared resource...
freeeezzzinggg......
>

Run your client in a thread. Instant anti-freeze.
I tried, with anti-freeze it stops freezing my computer, but it slows it
dramatically.
Again, if you unplug your running computer from the network and try to
access a shared resource, you will see you box will freeze for a while... I
get the same problem with my app
 

Re:check an in-network ip

MuZZy writes:
Quote
And again, if i connect to a 'dead' computer, my compuer is freezing.
Then you should put that specific part of the code into a thread of its
own. There's no other way with a firewall in between.
--
Ben
 

Re:check an in-network ip

"MuZZy" <XXXX@XXXXX.COM>writes
Quote
TcpClient.Connect;
Which specific component are you actually using?
Gambit
 

Re:check an in-network ip

"Remy Lebeau (TeamB)" <XXXX@XXXXX.COM>writes
Quote

"MuZZy" <XXXX@XXXXX.COM>writes
news:4046caca$XXXX@XXXXX.COM...

>TcpClient.Connect;

Which specific component are you actually using?

I am using TIdTcpClient and TIdTcpServer.
So when client tries to connect to server, i face three possibilities:
1. server is active - that is fine
2. server's computer is up but server itself is not running - then i get
"Socket Error", which i can handle, that is also fine.
3. Server computer is not working, so it is ip doesn't exist at the moment -
here i have problem - client is freezing.
Again, pinging ip address will not help, as the server might be behind a
router.
Also, if i run client in a separate thread, it will freeze, and it can
potentially create multiple frozen threads, which can cause system crash...
Please, Remy, any ideas on how to painlessly detect if remote
computer/server is active!
Thank you,
Andrey
 

Re:check an in-network ip

Quote
3. Server computer is not working, so it is ip doesn't exist at the moment -
here i have problem - client is freezing.

Again, pinging ip address will not help, as the server might be behind a
router.
Also, if i run client in a separate thread, it will freeze, and it can
potentially create multiple frozen threads, which can cause system crash...
I've got the same problem but when I try to access a computer
that's not on or accessable, the client will time out and raise
an exception. For me, it was about 25 seconds for the time out
to occur. When that happens, just clean up the thread and the
exception and the client should unfreeze. Not sure if this
helps but this is how I took care of the freezing. Also take a
look at the TidAntiFreeze component. It should help as well.
Thanks,
Vu Do
 

Re:check an in-network ip

"Vu Do" <XXXX@XXXXX.COM>writes
Quote

>3. Server computer is not working, so it is ip doesn't exist at the
moment -
>here i have problem - client is freezing.
>
>Again, pinging ip address will not help, as the server might be behind a
>router.
>Also, if i run client in a separate thread, it will freeze, and it can
>potentially create multiple frozen threads, which can cause system
crash...

I've got the same problem but when I try to access a computer
that's not on or accessable, the client will time out and raise
an exception. For me, it was about 25 seconds for the time out
to occur. When that happens, just clean up the thread and the
exception and the client should unfreeze. Not sure if this
helps but this is how I took care of the freezing. Also take a
look at the TidAntiFreeze component. It should help as well.

Thank you for a suggestion, Vu!
But problem is: every chat client has an address book with about 20-25
addresses, and my idea was to run an availability check on each address
during the program launch and i can not let each test freeze for 25 sec: 25sec
times 25 ips = approx 10 minutes :)
And if i launch each check in a separate process, i potentially can get 25
freezing threads, which doesn't seem to be a good idea as well :)
Any suggestions would be highly appreciated!
Thank you,
Andrey
 

Re:check an in-network ip

"MuZZy" <XXXX@XXXXX.COM>writes
Quote
I am using TIdTcpClient and TIdTcpServer.
Then you should be specifying a timeout when calling Connect(). It has an
ATimeout parameter. Otherwise, it will wait indefinately until the
underlying socket stack itself fails to connect, which might take awhile.
Quote
3. Server computer is not working, so it is ip doesn't exist
at the moment - here i have problem - client is freezing.
Indy is frozen until the underlying socket stack itself does something. If
the stack is frozen for awhile, then that is an OS issue, not an Indy one.
Quote
Please, Remy, any ideas on how to painlessly detect
if remote computer/server is active!
There is no single most effective way to handle that other than to actually
connect to the server and check for errors. Your first step should be to
use an actual timeout on the Connect() itself.
Gambit
 

Re:check an in-network ip

"Remy Lebeau (TeamB)" <XXXX@XXXXX.COM>writes
Quote

"MuZZy" <XXXX@XXXXX.COM>writes
news:404794c8$XXXX@XXXXX.COM...

>I am using TIdTcpClient and TIdTcpServer.

Then you should be specifying a timeout when calling Connect(). It has an
ATimeout parameter. Otherwise, it will wait indefinately until the
underlying socket stack itself fails to connect, which might take awhile.

>3. Server computer is not working, so it is ip doesn't exist
>at the moment - here i have problem - client is freezing.

Indy is frozen until the underlying socket stack itself does something.
If
the stack is frozen for awhile, then that is an OS issue, not an Indy one.

>Please, Remy, any ideas on how to painlessly detect
>if remote computer/server is active!

There is no single most effective way to handle that other than to
actually
connect to the server and check for errors. Your first step should be to
use an actual timeout on the Connect() itself.
I got your idea... but why there is a difference in client's behavior when
server is not up, but computer is running,
and when computer is shut down?
In both cases client tries to connect, but in first case it finds ip but
can't connect to server socket( and fires socket error ), in second case it
just can not find an ip ( and freezes )... Why it doesn't fire a socket error
if it can not find an ip?
Andrey
 

Re:check an in-network ip

Quote
But problem is: every chat client has an address book with about 20-25
addresses, and my idea was to run an availability check on each address
during the program launch and i can not let each test freeze for 25 sec: 25sec
times 25 ips = approx 10 minutes :)
You can change the timeout duration on the connect of the
client. You can use TidTCPClient.Connect(3000); for 3 seconds.
It doesn't have to be 25 seconds. that is my example.
Quote
And if i launch each check in a separate process, i potentially can get 25
freezing threads, which doesn't seem to be a good idea as well :)

If they were separate threads, each could potentially timeout
at 3 seconds or whatever you choose, rather than waiting for
each connection to timeout then going on to the next
connection. They would run in parallel rather serial.
Thanks,
Vu Do
 

Re:check an in-network ip

"Vu Do" <XXXX@XXXXX.COM>writes
Quote

>But problem is: every chat client has an address book with about 20-25
>addresses, and my idea was to run an availability check on each address
>during the program launch and i can not let each test freeze for 25 sec:
25sec
>times 25 ips = approx 10 minutes :)

You can change the timeout duration on the connect of the
client. You can use TidTCPClient.Connect(3000); for 3 seconds.
It doesn't have to be 25 seconds. that is my example.

>And if i launch each check in a separate process, i potentially can get
25
>freezing threads, which doesn't seem to be a good idea as well :)
>

If they were separate threads, each could potentially timeout
at 3 seconds or whatever you choose, rather than waiting for
each connection to timeout then going on to the next
connection. They would run in parallel rather serial.
Ok but then i have a question - is it ok for Win98 to have 25 frozen network
processes at the same time? Even for 3 sec, which obviousely will be much
more, because we don't have 'pure parallel-tasking' with only one processor,
especially on Windows 98...
I am not sarkastic, i just don't know...
Andrey
 

Re:check an in-network ip

Quote
more, because we don't have 'pure parallel-tasking' with only one processor,
especially on Windows 98...
Hmm... Good question. I am not sure with Win98.
Thanks,
Vu Do