dgram.createSocket(type[, callback])


创建指定 typedgram.Socket 对象。

一旦创建了套接字,则调用 socket.bind() 将指示套接字开始监听数据报消息。 当 addressport 没有传给 socket.bind() 时,则该方法会将套接字绑定到随机端口上的“所有接口”地址(它对 udp4udp6 套接字都做正确的事情)。 可以使用 socket.address().addresssocket.address().port 检索绑定的地址和端口。

Creates a dgram.Socket object of the specified type.

Once the socket is created, calling socket.bind() will instruct the socket to begin listening for datagram messages. When address and port are not passed to socket.bind() the method will bind the socket to the "all interfaces" address on a random port (it does the right thing for both udp4 and udp6 sockets). The bound address and port can be retrieved using socket.address().address and socket.address().port.