PerlIf you want to read and write simultaneously on a socket in Perl you have to set the socket to non-blocking mode. A socket is by default exclusive to reading OR writing. This means you can not write to a socket while you are reading from it.

IO::Socket::INET has a parameter “blocking” which should handle this but that didn’t work for me. However the search engine concept proved its purpose again and the following saved me:

# Create socket
my $sock = new IO::Socket::INET(PeerAddr    => 'localhost',
                                PeerPort    => '8080',
                                Proto       => 'tcp') or
                                    die "Can't connect to server: $!";

# Nonblocking mode
my $nonBlocking = 1;
ioctl($sock, 0x8004667e, \$nonBlocking);

# Read and write
...

Create your socket and after that use the ioctl function to manipulate it. Important is that you pass the variable by reference. Setting the argument directly or without reference does not work.