While trying to port some socket code from Java to Node.js (or rather, node-webkit) I came to the part where a handshake is performed between the client and the server. The Java code for this is simple (validation left out):While trying to port some socket code from Java