Hey,
I am making an IRC bot to bridge 2 channels on different networks.
For this I need to scan 2 sockets for data. How do I do this? This
is how I do 1 socket:
while(my $input = <$sock>)
{
.........
}
--
Dave
All us base are belong to you.
QUOTE |
I am making an IRC bot to bridge 2 channels on different networks. |
QUOTE |
Hey, I am making an IRC bot to bridge 2 channels on different networks. For this I need to scan 2 sockets for data. How do I do this? This is how I do 1 socket: while(my $input = <$sock>) { ......... } |
QUOTE |
Well, I have tried some modules, etc, but none of them have been properly documented, or made the documentation available to any mortals. After trying out a few, I prefered to do the socket programming myself. |
QUOTE |
If I do use select for sockets, or something, i.e: while(1) { if(my $input = <$sock1>) { ...... } if(my $input = <$sock2>) { ...... } } Won't it just sit on $sock1 waiting for data until it gets some, whilst messages could be pouring in unread on $sock2? |
QUOTE |
Also, is select necessary - can't you just use each sock my name, instead of by default? |
QUOTE |
Please group reply to prevent getting accidentally ignored and so everyone can help and be helped. Also please bottom post. |
QUOTE |
Though it is more of a server rather than client example. Essentially you open the filehandles (sockets) you want to read from, add them to an IO::Select object, then ask that object for a list of handles ready to be read from. Then just read from the handle. On the same token you should really be using IO::Socket::* instead of messing with the sockets directly. |
QUOTE |
If it is good enough for Mr. Stein, it is good enough for *almost* all of us. |
QUOTE |
On the same token you should really be using IO::Socket::* instead of messing with the sockets directly. |
QUOTE |
Having said all of this, it still isn't truly multitasking because you can still block on a socket that had a lot of data or a slow socket. This method presumes that your CPU and IO handler is fast enough to prevent the appearance of a slow down because of blocking. |
QUOTE |
perldoc -f select Good luck, |
QUOTE |
Uhhh.... I can't believe I just posted it non-list again. Here it is for the list: |
QUOTE |
On 7/8/05, Wiggins d'Anconia <[Email Removed]> wrote: Please group reply to prevent getting accidentally ignored and so everyone can help and be helped. Also please bottom post. Whoops - sorry about that - Gmail must have picked your email address instead of the list when I hit the reply button. Though it is more of a server rather than client example. Essentially you open the filehandles (sockets) you want to read from, add them to an IO::Select object, then ask that object for a list of handles ready to be read from. Then just read from the handle. On the same token you should really be using IO::Socket::* instead of messing with the sockets directly. Aha - I must have confused it with some other select - I thought select() just selected which socket is the default. |
QUOTE |
If it is good enough for Mr. Stein, it is good enough for *almost* all of us. Mr Stein? |
QUOTE |
On the same token you should really be using IO::Socket::* instead of messing with the sockets directly. Umm... I am using IO::Socket::INET |
QUOTE |
Having said all of this, it still isn't truly multitasking because you can still block on a socket that had a lot of data or a slow socket. This method presumes that your CPU and IO handler is fast enough to prevent the appearance of a slow down because of blocking. Well, I wasn't really worried about slowdowns, but a blocking socket would be a real problem with my application - One channel could be sending lots and lots of messages, which wouldn't be relayed because the program is busy blocking on the other socket. |
QUOTE |
perldoc -f select Good luck, Thanks - I just looked at the website you pointed to - it looks perfect for what I need. The server code example is amazingly clean, simple and elegent - I will certainly use this for all multi-socket apps in future |