M
M
MaKS_Ibl42017-07-24 13:07:06
Node.js
MaKS_Ibl4, 2017-07-24 13:07:06

Why does an error occur when connecting to socket io?

We have the following server code:

var https = require('https'),     
    fs =    require('fs'); 
const opts = {
  key: fs.readFileSync('/home/admin/conf/web/ssl.key'),
  cert: fs.readFileSync('/home/admin/conf/web/ssl.crt')
}
var app = https.createServer(opts);
var io = require('socket.io').listen(app);
app.listen(8091, function(){
  console.log("HTTPS on port " + 8091);
})

I have already changed it several times, before that it was express, but the essence is the same.
On the client: And when visiting the page: WebSocket connection to 'wss://domain:8091/socket.io/?EIO=3&transport=websocket&sid=zDddBcCarJyExmO9AAAD' failed: WebSocket is closed before the connection is established. Where to dig? With what this problem can be connected? ps: as practice has shown, the matter is in the encoding, but it is not clear where exactly the problem is. If a user with a Russian name and surname enters, such a problem, if with English, then everything is fine. If you send a message to the chat, then when you refresh the page and load the history, so to speak, you can catch: socket.io.js:6783 Uncaught Error: Illegal attachments at decodeString (socket.io.js:6783)
var socket = io.connect(':8091');
at Decoder.add (socket.io.js:6731)
at Manager.ondata (socket.io.js:418)
at Socket. (socket.io.js:1512)
at Socket.Emitter.emit (socket.io.js:4389)
at Socket.onPacket (socket.io.js:2514)
at XHR. (socket.io.js:2331)
at XHR.Emitter.emit (socket.io.js:4389)
at XHR.Transport.onPacket (socket.io.js:2947)
at callback (socket.io.js:3821)
pss: I'm even ashamed to write the cause of the problem, the old version of socket.io is on the client side, since the server hasn't been updated in LAN for a long time, and after transferring from git to vps, it turned out that the server is the latest, and the client is from the old days)))

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
MaKS_Ibl4, 2017-07-24
@MaKS_Ibl4

The problem is in the old version of socket io client-side))) Thank you all for your help.

E
emp1re, 2017-07-24
@emp1re

var io = require('socket.io'). listen (app)

D
de1m, 2017-07-24
@de1m

Look at this example. The example itself may not be very good, but the socket is attached well.
You should try to use standard ports (80,443) whenever possible, since all others can be blocked on the client. The example uses ports 5000,5001, but they can be easily changed to the ones you need.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question