in reply to Socket IO problems

is $encrypted_message binary? if so, it might contain your EOL marker. An easy solution is to send the length first, and then read that number of bytes:
# client print SOCK length($msg) . "\n" . $msg; #server: chomp( $len = <SOCK> ); read(SOCK, $msg, $len );
--Dave