in reply to Simple Msg/Response Socket Setup

This is a basic example of IO::Socket. Check the POD again coz this is where I learnt it from.
#!/usr/bin/perl -w #Client use strict; use IO::Socket::INET; my $remote_host = "127.0.0.1"; #define remote host... local host now p +robably my $remote_port = 5050; #define port here my $socket = IO::Socket::INET->new( PeerAddr => $remote_host, PeerPort => $remote_port, Proto => "tcp", Type => SOCK_STREAM) || die "Can't connect to $remote_host:$remote_port -> $!\n"; print $socket "Quoth the Raven\n"; my $answer = <$socket>; print $answer; close($socket);




#!/usr/bin/perl -w #Server use strict; use IO::Socket::INET; my $local_port = 5050; #Define a port my $server = IO::Socket::INET->new( LocalPort => $local_port, Reuse => 1, Listen => SOMAXCONN, Type => SOCK_STREAM) || die "Can't start server on $local_port -> @!\n"; my $client = undef; my $user = undef; my $file = undef; print "accepting connections...\n"; while($client = $server->accept()) { $client->autoflush(1); my $line = undef; if(defined($line = <$client>)) { print "received :", $line; print $client "nevermore"; } close($client); } close($server);
Enjoy!

Greetz
Beatnik
... Quidquid perl dictum sit, altum viditur.