What I want to do is setup a simple node.js http server to which a
web-client connects. I also want the node.js server to act as a UDP
listener on a separate port, on which it will receive udp packages from
some other application. I want the node.js server to process the packages
and send it immediately to one or more of the connected web-clients. (Yes,
the UDP contains video stream that I already divided into smaller chunks
and put index on each chunk). Basically - there was already very similar
topic on stack overflow, however the guy over there wanted to parse the
JSON data, and I want to transfer bytes from live video stream.
Here's the code that was mentioned before on stack:
1.
Create a simple node.js http server that responds with a static html
page:
//Initialize the HTTP server on port 8080, serve the index.html pagevar
server = http.createServer(function(req, res) {
res.writeHead(200, {
'Content-type': 'text/html'});
res.end(fs.readFileSync(__dirname + '/index.html'));
}).listen(8080, function() {
console.log('Listening at: 127.0.0.1 8080');
});
2.
Initialize a UDP server on a separate port:
//Initialize a UDP server to listen for json payloads on port 3333var srv =
dgram.createSocket("udp4");
srv.on("message", function (msg, rinfo) {
console.log("server got: " + msg + " from " + rinfo.address + ":" +
rinfo.port);
io.sockets.broadcast.emit('message', 'test');
//stream.write(msg);
//socket.broadcast.emit('message',msg);});
srv.on("listening", function () {
var address = srv.address();
console.log("server listening " + address.address + ":" + address.port);});
srv.bind(5555);
3.
Use socket.io to establish a live connection between web-client and
server:
//this listens for socket messages from the client and broadcasts to all
other clientsvar io = require('socket.io').listen(server);
io.sockets.on('connection', function (socket) {
socket.on('message', function (msg) {
console.log('Message Received: ', msg.data.skeletons[0] ?
msg.data.skeletons[0].skeleton_id : '');
socket.broadcast.emit('message', msg);
}
);});
I guess my problem is I don't know how to bridge 2 and 3, to get the
received UDP packets broadcasted to the connected socket.io clients. Or
perhaps there's a simpler, more elegant way of doing this? I found the
documentation for socket.io to be lacking... Is anyone able to help me?
Thanks guys!
--
Job board: http://jobs.nodejs.org/
New group rules:
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/nodejs/4fd952fb-42fd-4e25-8c9a-cd9affb5d6df%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.