This question has already been answered:
- websocket shuts down due to idle php 2 response
There is a WebSocket, there is a code which receives data and sends, in general, everything is as it should be. Everything works, but not for long, after a short time (a couple of minutes) and small manipulations (page updates, etc.), the socket stops receiving messages and I get the following data from onclose:
On the server side, I use this library: https://github.com/pmill/php-chat
On the Internet, there is very little information about this and unfortunately very little I understand in which direction to dig.
Here is my js code:
submit_msg.unbind('click').click(function () { var message = input_message.val().trim(); if (message !== '') { sendChatMessage(); input_message.val(''); } input_message.focus(); return false; }); function connectToSocket() { conn = new WebSocket('ws://localhost:2222'); } // ЭТО Я ПЫТАЛСЯ ВОЗОБНОВЛЯТЬ СОЕДИНЕНИЕ ЕСЛИ ОНО ЗАКРОЕТСЯ function trackingStateWS() { interval_tracking_status_ws = setInterval(function() { if (conn.readyState === conn.CLOSED) { conn.close(); connectToSocket(); } }, 5000); } function connectToChat() { connectToSocket(); trackingStateWS(); conn.onopen = function () { var params = { // my params }; conn.send(JSON.stringify(params)); }; conn.onmessage = function (e) { var data = JSON.parse(e.data), date = new Date(data.timestamp * 1000); // ОБРАБОТКА ПРИХОДЯЩИХ ДАННЫХ }; conn.onclose = function(e) { console.log(e); }; conn.onerror = function (e) { console.log(e); }; return false; } function sendChatMessage() { var params = { // my params }; conn.send(JSON.stringify(params)); return false; } ADDED
When a web socket stops sending messages from clients, they can still connect to the web socket and have their status "online". It turns out onopen always works, and onmessage stops working after a couple of minutes.

