Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Reading from Multiple Ports

by madhatter (Sexton)
on Jan 29, 2001 at 02:24 UTC ( #54902=perlquestion: print w/replies, xml ) Need Help??
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.


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.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://54902]
Approved by root
[marto]: [id://1196212
[marto]: err same old song and dance I'm afraid

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (13)
As of 2017-07-28 15:28 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (431 votes). Check out past polls.