use IO::Socket::INET; # auto-flush on socket $| = 1; # creating a listening socket my $socket = new IO::Socket::INET ( LocalHost => '127.0.0.1', LocalPort => '7777', Proto => 'tcp', Listen => 5, Reuse => 1 ); die "cannot create socket $!\n" unless $socket; print "server waiting for client connection on port 7777\n"; while(1) { # waiting for a new client connection my $client_socket = $socket->accept(); # get information about a newly connected client my $client_address = $client_socket->peerhost(); my $client_port = $client_socket->peerport(); print "connection from $client_address:$client_port\n"; # read up to 1024 characters from the connected client my $data = ""; $client_socket->recv($data, 1024); print "received data: $data\n"; # write response data to the connected client $data = "ok"; $client_socket->send($data); # notify client that response has been sent shutdown($client_socket, 1); } $socket->close(); #### #!/usr/bin/perl use IO::Socket::INET; $| = 1; my $socket = new IO::Socket::INET ( PeerHost => 'theaddressofmycomputer.com', PeerPort => '7777', Proto => 'tcp', ); die "Cannot connect to the server $!\n" unless $socket; print "Connected to the server!\n"; my $req = "Hello World\n"; my $size = $socket->send($req); print "Sent data of length $size\n"; shutdown($socket, 1); my $response = ""; $socket->recv($response, 1024); print "Recieved response: $response\n"; $socket->close();