I
I
ispotz2017-09-06 16:32:47
Node.js
ispotz, 2017-09-06 16:32:47

How to pass value from UDP message to SIO connection function?

Good afternoon!
Please tell a beginner in js to a student.
Essence - 1 the server sends the address of the socketio server via UDP
2 the server must connect to the received address to the socketio server /
in the message comes `192.168.1.1:3000 for example - this is the address of the sio server, how to make it connect to this address
Code 2 server.

const client = require('dgram').createSocket('udp4').bind(5007);//port
var message;
client.on('listening', function () {
    client.setBroadcast(true)
    client.setMulticastTTL(128); 
    client.addMembership('224.1.1.1');
    console.log('Client waiting');
});
client.on('message', function (message, remote) {   
    console.log('Epic message received from: ' + remote.address + ':' + remote.port);
    console.log('SIO server at: ' + message);
    client.close();
});
var socket = require('socket.io-client')(message);
socket.on('connect', function(){
    console.log('connect')
});
socket.on('event', function(data){
    console.log('event ',data)
});
socket.on('disconnect', function(){
    console.log('disconnect')
});

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