var dgram = require('dgram') var server = dgram.createSocket("udp6") 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) }) server.bind(8888)
创建一个客户端
1 2 3 4 5 6 7
var dgram = require("dgram") var message = "wwwwweekend" var client = dgram.createSocket("udp6") client.send(message,0,message.length,8888,"localhost",function( err,bytes){ client.close() })