日期:2014-05-16 浏览次数:20860 次
var port=12345;
var dgram = require("dgram");
var server = dgram.createSocket("udp4");
server.on("message", function (msg, rinfo) {
var dgram2 = require('dgram');
var message = new Buffer("i recice");
var client = dgram2.createSocket("udp4");
client.send(message, 0, message.length, rinfo.port, rinfo.address, function(err, bytes) {
client.close();
});
console.log("server got: " + msg + " from " + rinfo.address + ":" + rinfo.port);
});
server.on("listening", function () {
var address = server.address();
console.log("server listening " + address.address + ":" + address.port);
});
server.bind(port);