标签:nodejs
var dgram = require('dgram'); var server = dgram.createSocket("udp4"); server.on("message",function(msg,rinfo) { 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); });
var dgram = require('dgram'); var message = new Buffer("send from client"); var client = dgram.createSocket("udp4"); client.send(message,0,message.length,41234,"localhost",function(err,bytes) { client.close(); });
标签:nodejs
原文地址:http://blog.csdn.net/rainlesvio/article/details/41597759