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


dgram.Socket 关联到远程地址和端口。 此句柄发送的每条消息都会自动发送到该目标。 此外,套接字将只接收来自该远程对等方的消息。 尝试在已连接的套接字上调用 connect() 将导致 ERR_SOCKET_DGRAM_IS_CONNECTED 异常。 如果未提供 address,则默认使用 '127.0.0.1'(适用于 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, '127.0.0.1' (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.