Port UDP socket to node.js from application to HTTP

Is it possible to transfer the Socket coming from the application to http through NodeJS?

I am sending my socket with the application (in C ++) to UDP or TCP (if this is not possible in UDP ...) to NodeJS.

My script from NodeJS:

var server = dgram.createSocket("udp4"); 
server.on("message", function (content, rinfo) 
{ 
   console.log("socket: " + content + " from " + rinfo.address + ":" + rinfo.port); }); 
   server.on("listening", function () { 
}); 
server.bind(7788);

This function is still there, but then, how to transfer my socket to Socket.io for example?

I want to send a socket to Socket.io (for example) to send the socket to HTTP. Using such a function, for example, but not updating the connection with socket.io:

io.sockets.on('connection', function (socket) { 
    socket.emit(content);
});

Thank you for your help.

++ Metra.

+5
source share
1 answer

socket.io, -, ( ), UDP , :

var http = require('http'),
    dgram = require('dgram'),
    socketio = require('socket.io');

var app = http.createServer(handleRequest),
    io = socketio.listen(app),
    socket = dgram.createSocket('udp4');

socket.on('message', function(content, rinfo) {
    console.log('got message', content, 'from', rinfo.address, rinfo.port);
    io.sockets.emit('udp message', content.toString());
});

function handleRequest(req, res) {
    res.writeHead(200, {'content-type': 'text/html'});
    res.end("<!doctype html> \
        <html><head> \
        <script src='/socket.io/socket.io.js'></script> \
        <script> \
            var socket = io.connect('localhost', {port: 8000}); \
            socket.on('udp message', function(message) { console.log(message) }); \
        </script></head></html>");
}

socket.bind(7788);
app.listen(8000);

:. io.sockets.emit, , UDP- 7788, . , Socket.IO "room": io.sockets.of(someRoom).emit. Socket.IO join - .

+8

All Articles