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

Reading from Multiple Ports

by madhatter (Sexton)
on Jan 29, 2001 at 02:24 UTC ( [id://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.

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.

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
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2024-04-19 07:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found