This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

detect server

Old posts that have not been replied to for several years.
Locked
V
VaVaVooM
Voice
Posts: 10
Joined: Thu Feb 13, 2003 8:30 am
Location: Portugal

detect server

Post by VaVaVooM »

hi

how can i find out if a certain server is online, and if he has a port open to incoming connections?
the server to check is a game server..
i tried this:

Code: Select all

   set sidx ""
   set sidx [connect $srvrhost $srvrport]
    if {$sidx == ""} {
     putserv "privmsg $chan :Server is offline"
    } else {
     putserv "privmsg $chan :Server is online"
    }
but i always get a valid idx, even if i can't connect!!!

another problem, is that if i get a DNS error the script blocks :|

bye
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

By using socket instead of connect (http://tcl.tk/man/tcl8.4/TclCmd/socket.htm)

something like this...

Code: Select all

if {[catch {socket $srvrhost $srvrport} x]} {
    putserv "privmsg $chan :Server is offline ($x)" 
} else {
    putserv "privmsg $chan :Server is online"
    close $x
}
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

One question.

You are saying that if you give a hostname that doesn't resolve, the script blocks forever, or until a resolve error occurs?

If you are on about the resolve error, of cause it has to block. How on earth can it attempt to connect, until it has the IP address?


On top, the documentation states that the sockets are asynchronous, meaning they return right away, regardless of connection status. This is documented in the last part of tcl-commands.doc
V
VaVaVooM
Voice
Posts: 10
Joined: Thu Feb 13, 2003 8:30 am
Location: Portugal

Post by VaVaVooM »

hey []

Thanks user :)

ppslim: The script blocks forever, or until i do a .rehash.. By the way, the script is activated by a public command..

This time, i read that part of the sockets beeing asynchronous at tcl-commands.doc :wink: , but i thought that it had to return a value that could be distinguished.. For this i tried to use the valididx command, but he always returned a valid connection (idx).. And that was the main problem of the script.

bye []
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

I havn't checked, but with that valid IDX, you may be able to perform lsearch requests on the output from dccstat.

Aditionaly, it can't be blocking forever. If you are able to rehash, then there is no block. Block means the code is at a point, where another program, or some code has to return, before the main loop can continue.

The main loop must be running if eggdrop is able to read the socket, and process your rehash command.

As such, can you define the differance between using it on a valid address, and one that results in what you called a blcok?
V
VaVaVooM
Voice
Posts: 10
Joined: Thu Feb 13, 2003 8:30 am
Location: Portugal

Post by VaVaVooM »

I don't think i can..

But anyway, the problem is solved by using the socket instead of connect, since this doesn't gets jammed when a host doesn't resolve..
And it always returns something.. And that was what i was looking for..

thanks again.. :)
Locked