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

Reading from Multiple Ports

by madhatter (Sexton)
on Jan 28, 2001 at 21:24 UTC ( [id://54902]=perlquestion: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.

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 28, 2001 at 21: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 12: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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://54902]
Approved by root
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.