Well, since it looks like you've already solved your problem, I'll give you a heads up for the thing that cause me some confusion/grief when I started learning sockets.
When you send() data, it won't necessarily all arrive in one recv() call. e.g. If you $server->send('abcde'), you may receive it as 'abc' followed by 'de' in your next loop.