Сводка:
Я пытаюсь запустить сервер WebSocket, используя Ratchet и ReactPHP на моем VPS. Однако при выполнении Server.php я получаю следующую ошибку: < /p>
PHP Fatal error: Uncaught RuntimeException: Failed to listen on "tcp://0.0.0.0:2053": Address already in use (EADDRINUSE) in /var/www/meetwithchat/vendor/react/socket/src/TcpServer.php:188
< /code>
Даже после убийства процесса, который, по -видимому, использует порт 2053, новый процесс автоматически перезапускается и связывает с тем же портом. Следовательно, мой код на стороне клиента в script.js не может установить соединение WebSocket. < /P>
Я также получаю < /p>
WebSocket connection to 'wss://meetwithchat.com:2053/' failed:
< /code>
Ошибка на консоли Chrome. < /p>
server.php:
< /code>
script.js:
let ws = new WebSocket("wss://meetwithchat.com:2053/");
ws.onopen = function () {
// Send initial messages to set gender and preference
ws.send(JSON.stringify({ type: "setGender", gender: genderValue }));
ws.send(JSON.stringify({ type: "setPreference", preference: preferenceValue }));
};
ws.onmessage = function (event) {
const data = JSON.parse(event.data);
if (data.type === "match") {
// Handle a successful match
} else if (data.type === "message") {
// Append message to chat UI
} else if (data.type === "chatEnded") {
alert("Partner has left the chat. Chat ended!");
resetChat();
}
};
ws.onclose = function () {
resetChat();
};
Подробнее здесь: https://stackoverflow.com/questions/794 ... php-on-vps