accept method

  1. @override
Future<SocksUdpClientBoundSocket> accept({
  1. bool? connect,
  2. bool? allowIPv6,
})
override

Accept connection.

TCP: If connect is true this function will open connection to requested host.

Mustn't throw any errors.

Implementation

@override
Future<SocksUdpClientBoundSocket> accept({
  bool? connect,
  bool? allowIPv6,
}) async {
  final clientBoundSocket =
      SocksUdpClientBoundSocket(
    await RawDatagramSocket.bind(InternetAddress.anyIPv4, 0),
  );

  add([
    0x05, // Socks version.
    0x00, // Succeeded.
    0x00, // Reserved byte.
    0x01, // IPv4
    0x00, 0x00, 0x00, 0x00, // 0.0.0.0
    // Convert short port to big endian byte list.
    (clientBoundSocket.port & 0xff00) >> 8, clientBoundSocket.port & 0xff,
  ]);
  await flush();

  return clientBoundSocket;
}