javascript - how to transfer data received from UDP to the webpage in node.js -


i'm running 2 apps here. have client:

var port = 5007 ;   var dgram = require('dgram');   var client = dgram.createsocket('udp4');    client.on('listening', function () {       var address = client.address();       console.log('udp client listening on ' + address.address + ":" + address.port);       client.setbroadcast(true)       client.setmulticastttl(128);        client.addmembership('224.1.1.1');   });    client.on('message', function (message, remote) {          console.log('a: epic command received. preparing relay.');       console.log('b: from: ' + remote.address + ':' + remote.port +' - ' + message);   });    client.bind(port); 

and server:

var port = 5007 ;   var dgram = require('dgram');   var client = dgram.createsocket('udp4');    client.on('listening', function () {       var address = client.address();       console.log('udp client listening on ' + address.address + ":" + address.port);       client.setbroadcast(true)       client.setmulticastttl(128);        client.addmembership('224.1.1.1');   });    client.on('message', function (message, remote) {          console.log('a: epic command received. preparing relay.');       console.log('b: from: ' + remote.address + ':' + remote.port +' - ' + message);   });    client.bind(port); 

it works pretty well, when run in 2 separates consoles - see transfer going , messages appear on both sites. now, how can display/transfer data webpage? thanks!

well depends on type of data combined if want real-time or served upon request.

if want served upon request, you'd have store data somewhere can accessed @ later point. either on filesystem or in mongodb's gridfs, or either directly in database (as said, depending on type of data is)

if want streamed real-time connected web clients you'd have use socket.io or webrtc. difference between 2 significant. socket.io simple work requires man-in-the-middle server whereas webrtc (web real-time communications) directly peer-to-peer in browser , lot harder work with. webrtc new , isn't available in older browser versions, i'd suggest going socket.io or similar in case.

hopefully better overview on possibilities have. either way need catch data somewhere between 2 clients (as shown in client-server example)


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -