engine.io
engine.io copied to clipboard
Behavior outside of spec
Hi!
For a project that I'm working on, I would like to connect through websockets first, and fall back on polling later on. Although not officially supported by the engine.io protocol, the Socket.IO manual specifically mentions this possibility, see 'With websocket transport only'.
When trying this with the engine.io and socket.io haskell library, this does not work. However, trying the following node.js setup with the socket.io implementation, it connects perfectly.
app.js
const io = require('socket.io-client');
var socket = io("http://localhost:4004", {path:"/mysocket", transports:['websocket']});
socket.on('connect', ()=>{
console.log('connected');
});
Server.js
var io = require('socket.io')(4000,{path:"/mysocket"});
io.on('connection', (socket)=> {
console.log('connection');
});
Looking at the logs wireshark creates, the issue seems to be the reply that the server sends: while the js implementation sends a response 101 (Switching Protocols), the haskell implementation responds with a 200 (OK), which is the default response at the end of the 'freshSession' function.
@Matthiasvanderhallen what version of socket-io client was used for testing?
It looks like haskell implementation doesn't support socket-io 2.x.x
. Chat example works with 1.2.1
.
I can confirm the issue.
With both types of transport enabled client at first made polling
request and receives session ID in response:
{
"sid": "F6Mn22TqNwMfRJhVAAAD",
"upgrades": [
],
"pingInterval": 25000,
"pingTimeout": 5000
}
After this client made request with websocket
transport request with sid
in query param. After this server upgrade the connection to websocket
.
In case of websocket
only transport. Client made websocket
request and should receive first message with such json from server via websocket connection.
It looks like haskell server doesn't handle this part correctly, it always expects sid
in websocket
request in query params.