use IO::Socket; #To flush the buffer print statements $| = 1; my $sock = new IO::Socket::INET( PeerAddr => 'localhost', PeerPort => 7890, Proto => 'tcp'); if ($sock) { print "A tcp socket on localhost connected to 7890\n"; } else { die "Error: $!"; } $nonblocking = 1; ioctl($sock, 0x8004667e, \$nonblocking); $buf = "1234567890"; syswrite($sock, $buf, 10); sysread($sock, $buf, 10); $sock->flush; print "Bytes 10 = $buf\n"; syswrite($sock, "1", 1); print "\n"; $sock->flush; sysread($sock, $buf, 2); print "Bytes 2 = $buf\n"; #### use IO::Socket; $| = 1; my $sock = new IO::Socket::INET( LocalHost => "localhost", LocalPort => 7890, Proto => "tcp", Listen => SOMAXCONN, Reuse => 1, Timeout => 20 ); if ($sock) { print "A $Proto socket created on $LocalHost listening on $LocalPort\n"; } else { die "Error - no listening socket created : $!"; } $flush = 1; while (($new_sock,$c_addr) = $sock->accept()) { my ($client_port, $c_ip) = sockaddr_in($c_addr); my $client_ipnum = inet_ntoa($c_ip); my $client_host =gethostbyaddr($c_ip, AF_INET); print "Got a connection from: $client_host"," [$client_ipnum] \n"; print "Created new socket for reading or writing data to Client\n"; $nonblocking = 1; ioctl($new_sock, 0x8004667e, \$nonblocking); sysread($new_sock, $buf, 10); print "$buf\n"; syswrite($new_sock, $buf, 10); $new_sock->flush; sysread($new_sock, $buf, 1); print "$buf\n"; $new_sock->flush; syswrite($new_sock, "12", 2); }