Please consider my comments to the question as a big warning against this approach.
If you still want to use it, please see:
http://code.google.com/p/jsocket/[
^],
http://socket.io/[
^].
Try to find some more:
http://bit.ly/VpKzi9[
^].
[EDIT: in response to PHP-related discussion in comments:]
This is how you can do it in PHP. For server side, with PHP in particular, custom networking is way more usual, by the reasons I tried to explain in comments to the question (please see the on on PHP) and this answer:
http://php.net/manual/en/ref.sockets.php[
^].
—SA