Skip to main content
Socket.prototype.connect - node__dgram.d.ts - Node documentation
method Socket.prototype.connect

Usage in Deno

```typescript import { Socket } from "node:node__dgram.d.ts"; ```
Socket.prototype.connect(
port: number,
address?: string,
callback?: () => void,
): void
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.

Parameters

port: number
optional
address: string
optional
callback: () => void
Called when the connection is completed or on error.

Return Type

void
Socket.prototype.connect(
port: number,
callback: () => void,
): void

Parameters

port: number
callback: () => void

Return Type

void