hi there!
I'm afraid its not going to be
that easy to do (I'm sorta trying to do the same thing.. and having terrible luck with it..)
this example might work for you.. assuming a "proper" internet connection... (something MY ISP doesn't offer)..
Code: Select all
set T "30"
set IP "123.45.67.89"
set Port "8080"
if {(![info exists loop])}
utimer $T [RunLoop1]
set loop 1
}
proc RunLoop1 {} {
SockTest
utimer $T [list RunLoop1]
}
proc SockTest{} {
if {([catch {set Sock [socket $IP $Port]}])} {
putlog "Connection Not Present"
return 0
} else {
close $Sock
putlog "Connection Present"
return 0
}
}
The problem with the above example is your eggdrop might "freeze" while the connection is being tested.. depending on some situations (such as mine) this could become a problem..
the following might be better then:
Code: Select all
set IP "123.45.67.89"
set Port "8080"
set T "30"
if {(![info exists loop])}
utimer $T [RunLoop1]
set loop 1
}
proc RunLoop1 {} {
SockTest
utimer $T [list RunLoop1]
}
proc SockTest {} {
if {([catch {set Sock [socket -async $IP $Port]; fconfigure $Sock -blocking 0;}])} {
putlog "Connection Not Detected"
return 0
} else {
close $Sock
putlog "Connection Detected"
}
}
NOTES:
IP = server/connection to be tested
Port = port of formentioned server
T = time in seconds to wait between test operations
CaSe CoUnTs! if you copy, copy carefully!
examples were derived from FreeBSD 6x (you may need to adjust the code for your particular OS/distro)
The above examples will test the presence of a connection... but under some situations, will NOT detect the presence of a
remote host (such as, in my case, if the host's ISP proxies the connections!) in which case, it gets even MORE complecated and unreliable..
I'm STILL trying to resolve the issue of an infefinate lockup during handshaking.
My TCL coding skills are "old school".. and may be lacking newer techniques. Perhaps someone else can give ya something newer and better (assuming you have the latest versions on TCL and all nessessary packages installed/available on your shell/box.)
These examples are just "raw code" that addresses the connection-handling.. and doesn't include any actions such as what to DO with the tested resaults.. (it will NOT post to a chatroom, for example) The examples will post the resault to the log file.
the reason I didn't include "what to do", is because the orginating poster didn't specify what he wanted the result/outcome to be. the examples given will post the tested result to the log file.
I hope this helps... Good luck!
-DjZ-
