I've created a node server on top of expressJs and used socket.io to create a websocket server. Code i've used to create the server is
io.sockets.on('connection', function (socket) {
connections.push(socket);
console.log('Connected: ' + connections.length + 'sockets connected');
io.sockets.emit('connected', JSON.stringify({status: "online"}));
socket.on('disconnect', function (data) {
connections.splice(connections.indexOf(socket), 1);
console.log('Disconnected: ' + connections.length + ' sockets connected');
io.sockets.emit('disconnected', {status: "offline"});
});
socket.on('request', function (data) {
console.log('new request in server: ' + data.toString());
io.sockets.emit('newRequest', JSON.stringify({request: data}));
})
});
I can connect with the server from any browser including mobile and emulator browser, But i failed to connect using okhttp3 websocket.
I am following https://gist.github.com/AliYusuf95/557af8be5f360c95fdf029795291eddb this gist to create the client. but i failed to connect with the websocket. I'm getting the following error
D/OkHttp: <-- HTTP FAILED: java.io.IOException: unexpected end of stream on Connection{192.***.0.***:3000, proxy=DIRECT@ hostAddress=/192.***.0.***:3000:3000 cipherSuite=none protocol=http/1.1}
What's going wrong?