Is it possible to transfer a Socket coming from a application to http via NodeJS?
I send my socket with a application (in c++) in UDP or TCP(if impossible 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);
Up to now does that function, but then how to transfer my socket to Socket.io for example?
I would like to send the socket to Socket.io (for example) for transfer the socket to HTTP. By using a function like this for example, but without renew a establishing a connection to socket.io :
io.sockets.on('connection', function (socket) {
socket.emit(content);
});
Thanks you for your help.
++ Metra.
Here's a complete example with a socket.io server, a web server sending out a very simple page (it will just log all messages to console) and an UDP socket listening for messages, passing them to all connected clients:
Update: As
io.sockets.emit
shows, all messages received on the UDP port 7788 are sent to all connected clients. If you want to route them based on some data in the message or similar, you could use Socket.IO's "room" feature:io.sockets.of(someRoom).emit
. In the connection handler for Socket.IO, you canjoin
each client to some room.