Because WebSocket is not a normal, general-purpose socket. It requires the server on the remote end to conform to a very specific handshake defined by the WebSocket protocol. If your server does not implement this protocol, WebSocket cannot connect to it.
Additionally, as Rocket points out, your code is currently attempting to call
socket.onopen() and assign a value to the function call. Lose the parentheses.