Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

IO::Socket vs IO::Socket::INET for simple webserver

by corwin18 (Initiate)
on Oct 18, 2011 at 20:26 UTC ( #932241=perlquestion: print w/replies, xml ) Need Help??
corwin18 has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to create a very simple webserver which can write to and read from a socket. I have been getting several different suggestions to use either IO::Socket or IO::Socket::INET. I don't know which would be better and why. Could someone please give me a quick explanation thanks!

This is what I have so far for my code, please any suggestions are very appreciated!

use IO::Socket::INET; my $socklist = new IO::Socket::INET (Listen =>1, LocalHOST =>'localhost', LocalPort => 6500, Proto => 'tcp', Reuse => 1); die "I couldn't create socket: $!\n" unless $socklist; my $sock_acpt = $socklist->accept(); while($sock_acpt){ print $_; } close($socklist); my $sockcli = new IO::Socket::INET ( PeerAddr => 'Chromium', PeerPort => '6500', Proto => 'tcp', ); die "Could not create socket: $!\n" unless $sockcli; print $sockcli "hello there!\n"; close($sockcli);

Replies are listed 'Best First'.
Re: IO::Socket vs IO::Socket::INET for simple webserver
by ikegami (Pope) on Oct 18, 2011 at 22:33 UTC
Re: IO::Socket vs IO::Socket::INET for simple webserver
by Sewi (Friar) on Oct 19, 2011 at 05:35 UTC

      I am trying to build my own for a class assignment which is why I sent in the code. Thank you for your responses. Are there any suggestions for improving my code?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://932241]
Approved by BrowserUk
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2018-02-20 06:44 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (267 votes). Check out past polls.