var dgram = require(‘dgram’); var client = dgram.createsocket(‘udp4’); var port= 69; var host= '192.168.0.136' var message= new buffer('hello'); set interval(function() { client.send(message,0,message.length,port, host, function (err, bytes) { }); } , 10000); client.on('message', function(message) { var temp = message.tostring(); console.log(temp); });
this quick udp example made. udp message 'hello' sent server every 10 second. message received printed console. udp server set sends random number each time message received. rather printed console, want emit message html page , print on html page. can show quick example message showcased on output box in html page update new message. have researched , sources websockets can not emit udp packets, other otherwise. please me clarify this.
node js-
io.on('connection', function(socket){ client.on('message', function(message){ var temp= message.tostring(); io.emit('temp', temp); }); });
html -
<script> var socket = io(); socket.on('temp', function(temp){ $('#messages').html(temp); });
include above code in node js, message received client.on, emitted socket. html page has socket listener incoming messages.
Comments
Post a Comment