Wait for port/time, can you tell which is which?
[1/5] from: mat::eurogamer::net at: 15-Jun-2001 11:10
Hello folks,
This is a straightforward problem and I'm sure I'm missing something
obvious. However any help appreciated!
I've written this IRC bot in Rebol and it's absolutely marvellous if I
do say so myself. :) The only problem is that it can sometimes be
disconnected from the server and it doesn't know about it. The same
happens to regular IRC clients too. As soon as you try to send
something, then it's apparent you have no socket and the bot/IRC
client reconnects etc. No problem.
The issue is using wait <port>, this will quite happily wait forever
obviously. I understand you can wait for a port AND a time, which is
nice. However, how could you tell whether wait has returned because
the duration timed out or that there was data at the port?
If there was no data and the wait timed out because of the duration,
currently I wouldn't know. I'd executing some sort of read from the
port which would result in a null string. You'd take that to mean
that the port is closed, right?
Which is no good. Instead, if the wait has timed out because of the
TIME limit then I just want to send some data to the server (a simple
ping in this case) and go back to my wait. If the socket is dead, then
the wait would return having data (even if there is none) and the bot
would reconnect because it was appropriate.
So how can you tell or is this the wrong approach entirely? Phew.
--
Mat Bettinson - EuroGamer's Gaming Evangelist with a Goatee
http://www.eurogamer.net | http://www.eurogamer-network.com
[2/5] from: m:koopmans2:chello:nl at: 15-Jun-2001 12:39
Wait returns none on a timeout, or the port that has activity.
Say x is your port.
Then wait [ 1 x ] returns either none or x.
Wait/all [ 1 x y z ]
returns either none or a block with all port that have events.
HTH,
Maarten
[3/5] from: mat:0wnerage at: 15-Jun-2001 12:18
Heya Maarten,
MK> Wait returns none on a timeout, or the port that has activity.
I'm such a dipstick :)
--
Mat Bettinson - EuroGamer's Gaming Evangelist with a Goatee
http://www.eurogamer.net | http://www.eurogamer-network.com
[4/5] from: mat:0wnerage at: 15-Jun-2001 10:19
Hello folks,
This is a straightforward problem and I'm sure I'm missing something
obvious. However any help appreciated!
I've written this IRC bot in Rebol and it's absolutely marvellous if I
do say so myself. :) The only problem is that it can sometimes be
disconnected from the server and it doesn't know about it. The same
happens to regular IRC clients too. As soon as you try to send
something, then it's apparent you have no socket and the bot/IRC
client reconnects etc. No problem.
The issue is using wait <port>, this will quite happily wait forever
obviously. I understand you can wait for a port AND a time, which is
nice. However, how could you tell whether wait has returned because
the duration timed out or that there was data at the port?
If there was no data and the wait timed out because of the duration,
currently I wouldn't know. I'd executing some sort of read from the
port which would result in a null string. You'd take that to mean
that the port is closed, right?
Which is no good. Instead, if the wait has timed out because of the
TIME limit then I just want to send some data to the server (a simple
ping in this case) and go back to my wait. If the socket is dead, then
the wait would return having data (even if there is none) and the bot
would reconnect because it was appropriate.
So how can you tell or is this the wrong approach entirely? Phew.
--
Mat Bettinson - EuroGamer's Gaming Evangelist with a Goatee
http://www.eurogamer.net | http://www.eurogamer-network.com
[5/5] from: ptretter:charter at: 16-Jun-2001 13:23
Hi Mat, not sure I understand you problem is totally, but since I once
created an IRC bot I thought I would take a stab at it. As for knowing
whether a port is closed you should receive a "none" from the client on the
other end or server if it closes a connection. The problem you run into
alot of times is when the client doesnt close the port and you remain opened
listening for data as you have not received the string "none". Make sure
you understand that you will receive a string and not the literal 'none you
might be used to. It is therefore crucial that you create a portion of your
script to verify the connection is indeed alive or have it just timeout if
the connection is idle (which is what I prefer). I actually created an IRC
bot script that would connect or cycle thru a list of IRC servers and
connect. It worked very well and if got disconnected it would immediately
begin the perpetual cycle of reconnecting thru the list and starting at next
server. The script I made works well and is quite large but if I dig it up
I will try to send it to you as it also support DCC protocol and CTCP
protocol. It was my attempt to create a gateway between Instant messaging
and the IRC networks which I may finish someday.
Paul Tretter