socket.connect(port[, address][, callback])

dgram.Socket 关联一个远程地址和端口。 这个 socket 句柄发送的任何消息都会被发送到关联的远程地址。 而且,这个套接字会只接受来自那个远程同类的消息。 会导致一个 ERR_SOCKET_DGRAM_IS_CONNECTED 异常。 如果没有提供 address,会默认用 ''(适用于 udp4 套接字)或者 '::1'(适用于 udp6 套接字)。 一旦连接完成,一个 'connect' 会触发,并且可选的 callback 也会被调用。 为了防止失败,这个 callback 被调用或者调用失败触发一个 'error' 事件。

Associates the dgram.Socket to a remote address and port. Every message sent by this handle is automatically sent to that destination. Also, the socket will only receive messages from that remote peer. Trying to call connect() on an already connected socket will result in an ERR_SOCKET_DGRAM_IS_CONNECTED exception. If address is not provided, '' (for udp4 sockets) or '::1' (for udp6 sockets) will be used by default. Once the connection is complete, a 'connect' event is emitted and the optional callback function is called. In case of failure, the callback is called or, failing this, an 'error' event is emitted.