socketToSocket static method
Future<SocketConnector>
socketToSocket({
- SocketConnector? connector,
- required InternetAddress addressA,
- required int portA,
- required InternetAddress addressB,
- required int portB,
- DataTransformer? transformAtoB,
- DataTransformer? transformBtoA,
- bool verbose = false,
- bool logTraffic = false,
- Duration timeout = SocketConnector.defaultTimeout,
- IOSink? logger,
- Creates socket to
portA
onaddressA
- Creates socket to
portB
onaddressB
- Relays data between the sockets
Implementation
static Future<SocketConnector> socketToSocket({
SocketConnector? connector,
required InternetAddress addressA,
required int portA,
required InternetAddress addressB,
required int portB,
DataTransformer? transformAtoB,
DataTransformer? transformBtoA,
bool verbose = false,
bool logTraffic = false,
Duration timeout = SocketConnector.defaultTimeout,
IOSink? logger,
}) async {
IOSink logSink = logger ?? stderr;
connector ??= SocketConnector(
verbose: verbose,
logTraffic: logTraffic,
timeout: timeout,
logger: logSink,
);
if (verbose) {
logSink.writeln('socket_connector: Connecting to $addressA:$portA');
}
Socket sideASocket = await Socket.connect(addressA, portA);
Side sideA = Side(sideASocket, true, transformer: transformAtoB);
unawaited(connector.handleSingleConnection(sideA).catchError((err) {
logSink.writeln('ERROR $err from handleSingleConnection on sideA $sideA');
}));
if (verbose) {
logSink.writeln('socket_connector: Connecting to $addressB:$portB');
}
Socket sideBSocket = await Socket.connect(addressB, portB);
Side sideB = Side(sideBSocket, false, transformer: transformBtoA);
unawaited(connector.handleSingleConnection(sideB).catchError((err) {
logSink.writeln('ERROR $err from handleSingleConnection on sideB $sideB');
}));
if (verbose) {
logSink.writeln('socket_connector: started');
}
return (connector);
}