madhatter has asked for the wisdom of the Perl Monks concerning the following question:

I've got a program that uses a while(){} loop to wait for data incoming to a socket and processes it "real time". Is there a way to have it read data from multiple ports and stuff the incoming port into a variable? I'm using UDP and Socket::IO.

Any help would be appreciated.

Thanks
madhatter

Replies are listed 'Best First'.
Re: Reading from Multiple Ports
by Fastolfe (Vicar) on Jan 29, 2001 at 02:29 UTC
    You probably want to use non-blocking sockets (via IO::Socket even) in conjunction with IO::Select. I don't know what you mean by "multiple ports" in that you could mean multiple destinations or multiple source ports. Either way, the 'peeraddr' or 'peerhost' or 'peerport' method in IO::Socket will get the address of the remotely connected client, while 'sockaddr'/'sockhost'/'sockport' will do the same for the local end.
Re: Reading from Multiple Ports
by ahunter (Monk) on Jan 29, 2001 at 17:21 UTC
    I wrote a tutorial on this a while back. The key is select() (or IO::Select) and unbuffered IO. Note that nonblocking sockets are a bit of a red herring - you almost never need to use them in practice.

    Andrew.