I am trying to create a websocket connection to 'ws://echo.websocket.org' with socket.io-client, here is my code:
const url = 'ws://echo.websocket.org'
const io = require('socket.io-client');
console.log('websocket conneting : ', url);
const socket = new io(url, {
transports: ['websocket'],
path: '/',
});
socket.on('connect', function(){
console.log('connect')
});
the result is that the 'connect' event never happened, and no event happened, I have catched the headers by wireshark:
GET /?EIO=3&transport=websocket HTTP/1.1
Sec-WebSocket-Version: 13
Sec-WebSocket-Key: XHrqdeZVhzRlp1eijFgMfw==
Connection: Upgrade
Upgrade: websocket
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits
Host: echo.websocket.org
/*
response
*/
HTTP/1.1 101 Web Socket Protocol Handshake
Connection: Upgrade
Date: Thu, 27 Jul 2017 09:22:50 GMT
Sec-WebSocket-Accept: GBUm4nbYv7kGp9H24yfqX9hh930=
Server: Kaazing Gateway
Upgrade: websocket
it seems that the connection is established successfully, so, why the 'connect' event doesn`t happened?