One other thing. Make sure you put $socket->autoflush() immediately after you create the socket at the client side, and $session->autoflush() immediately after you accept the connection on the server side. In your current code the proper place to do a $socket->close() would be after the return from host_to_user.