JavaScript: connect

Connects the socket, unless already connected.