Answer the question
In order to leave comments, you need to log in
Nodejs how to pass ws message to php?
Site on Bitrix
I am writing a functional that should work on websocket
server.js:
var WebSocketServer = new require('ws');
var dnode = require('dnode');
// подключённые клиенты
var clients = {};
var webSocketServer = new WebSocketServer.Server({
port: 8081
});
webSocketServer.on('connection', function(ws) {
var id = Math.random();
clients[id] = ws;
console.log("новое соединение " + id);
ws.on('message', function(message) {
console.log(message);
clients[id].send(message);
});
ws.on('close', function() {
console.log('соединение закрыто ' + id);
delete clients[id];
});
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question