in reply to Reading and writing sockets

To be both the client and the server, set up the program as a server. This way you're always ready to accept a transmission. First you establish the connection:
$server = IO::Socket::INET->new( Listen => 5, LocalPort => 4000, Proto => 'tcp', Reuse => 1, Type => SOCK_STREAM ) or die "Can't create server socket: $!";
Then you wait for transmissions:
while ($client = $server->accept()) {
Within this while loop, you can both accept transmissions, and respond to $client with something like:
print $client $ack;

Hope this helps.