【发布时间】:2016-07-01 02:30:06
【问题描述】:
我正在运行来自here 的两个应用程序。所以我们有一个客户:
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);
和服务器:
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);
当我在两个单独的控制台中运行它时,它运行良好 - 我看到传输正在进行并且消息出现在两个站点上。现在,如何将所有这些数据显示/传输到任何网页? 谢谢!
【问题讨论】:
标签: javascript node.js udp