M
M
Mikhail Smirnov2020-11-03 16:07:55
PHP
Mikhail Smirnov, 2020-11-03 16:07:55

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];
    });
});


googled about dnode

The principle of operation should be as follows:
json comes from the client,
this json is passed to php (Bitrix)
data is processed on php and the result is returned to the client

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question