createSocket method

UDPSocket createSocket(
  1. UDX udx,
  2. String host,
  3. int port, {
  4. ConnectionId? localCid,
  5. ConnectionId? remoteCid,
  6. bool isServer = false,
})

Creates or retrieves a UDPSocket for a given peer.

For dialing: a second call for the same host:port returns the first socket. Inbound connections don't go through this; each one gets its own socket, keyed by its connection ID.

Implementation

UDPSocket createSocket(
  UDX udx,
  String host,
  int port, {
  ConnectionId? localCid,
  ConnectionId? remoteCid,
  bool isServer = false,
}) {
  final peerKey = '$host:$port';
  final existing = socketsByPeer[peerKey];
  if (existing != null) return existing;
  return _newSocket(udx, host, port, localCid: localCid, remoteCid: remoteCid, isServer: isServer);
}