in reply to Sending Socket peer to peer

It's easy for a beginner to get the concept of server and receiver confused. The correct terms are server and client. The server opens up the port and waits for incoming connections. The client "dials up" the server's IP address, and connects. So here is a server, note it just opens a port, and knows it's own ip address.
#!/usr/bin/perl #This is a version that can read and write #from as many clients as your machine supports. use strict; use warnings; use IO::Socket; my $server = IO::Socket::INET->new ( LocalPort => 1337, Type => SOCK_STREAM, Reuse => 1, Listen => 5 ) or die "could not open port\n"; warn "server ready waiting for connections..... \n"; my $client; while ($client = $server->accept()) { my $pid; while (not defined ($pid = fork())) { sleep 5; } if ($pid) { close $client; # Only meaningful in the client } else { $client->autoflush(1); # Always a good idea close $server; &do_your_stuff(); } } sub do_your_stuff { warn "client connected to pid $$\n"; while(my $line = <$client>) { print "client> ", $line; print $client "pid $$ > ", $line; } exit 0; }

Now a client to connect, note you specify the ip address and port.

#!/usr/bin/perl use IO::Socket::INET; use strict; my $socket = new IO::Socket::INET(Proto => "tcp", PeerAddr => 192.168.0.15, PeerPort => 1337); while (1) { print $socket "1234\n"; my $msg = <$socket>; print $msg; sleep(5); }

I'm not really a human, but I play one on earth Remember How Lucky You Are