tags:

views:

128

answers:

5

How to do socket programing in Perl? Is there any module for it?

I am trying to do socket programming in Perl. I want to know if there are any modules to do this.

And another one question: Is it possible to do the multiple servers listen to one port, or multiple client listen to one port through socket programming?

+1  A: 

IO::Socket module

Socket Programming in PERL

abmv
That is one awful article containing an awful lot of awful prose and awful code in a sea of awful ads written by someone who does not even know the name of the language completely negating the value of the link to `IO::Socket`.
Sinan Ünür
hey @ least that boy can read it! shughs
abmv
What is this "PERL" people keep talking about?
innaM
@Manni, PERL is a language similar to Perl, that is used only for CGI scripts. PERL is just like Perl, but does not include taint mode, strictures, warnings, or lexical scoping. It is not obvious from the syntax, but PERL is also closely related to JAVA.
daotoad
+5  A: 

Is it possible to do the multiple servers listen to one port, or multiple client listen to one port through socket programming?

This has nothing to do with Perl: Only one application can be listening on a given port at any given point in time.

Also, unless you are implementing a custom protocol, there is really no good reason to deal with sockets in Perl. There are excellent modules for all commonly used protocols.

Sinan Ünür
+5  A: 

About multiple programs using the same socket, see option ReusePort on IO::Socket::INET. This allows other programs to later listen on that port too. For more information on reuse, search for "SO_REUSEPORT" which is the C library option name.

See the discussion here for more info on scaling using that technique (if that's your intention): http://kerneltrap.org/mailarchive/linux-netdev/2008/8/7/2851754

Viorel
A: 

The perlipc doc has a gentle introduction to using sockets with some good example code.

mobrule
A: 

I always point folks to IO::Lambda. It's a beautifully elegant way to deal with sockets and file descriptors of any kind.

Jeff Ober