T
T
twintwin10032015-02-01 01:35:17
Node.js
twintwin1003, 2015-02-01 01:35:17

Spoof sockets when connecting to Node.js server?

I am writing a game server in Node.js using the express and socket.io modules.
There was a problem: when quickly opening and closing tabs (tabs with the address that the server is listening to), the socket.io module sometimes does not have time to properly disconnect. That is, after playing around with tabs, I have 1 active connection (1 tab in the browser), but this number may be different on the server.
I find out the total number of connections using io.engine.clientsCount;
Socket.io 1.3.2
I will listen to any options and suggestions :)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Timur Shemsedinov, 2015-02-01
@twintwin1003

You need to count the number of connections yourself, and increment it after exchanging the minimum necessary data with the client. Also, so that the sockets do not hang, you need to periodically send the so-called heartbeat (or ping) through the connection, if it is not there for a long time, then the connection is considered dead. I don’t see the slightest point in socket.io, in general, just native WebSockets in the browser work fine: var ws = new WebSocket('ws://127.0.0.1:80/api/connect.ws'); and let's go, everything is specified and works perfectly everywhere. From the server side, the library https://www.npmjs.com/package/websocket or look at the comprehensive solution habrahabr.ru/post/247543

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question