Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

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.


Comment on Reading from Multiple Ports
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
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (9)
As of 2014-09-18 12:45 GMT
Find Nodes?
    Voting Booth?

    How do you remember the number of days in each month?

    Results (114 votes), past polls