serverToServer static method
Future<SocketConnector>
serverToServer({
- InternetAddress? serverAddressA,
- InternetAddress? serverAddressB,
- int? serverPortA,
- int? serverPortB,
- bool? verbose,
Binds two Server sockets on specified Internet Addresses. Ports on which to listen can be given but if not given a spare port will be found by the OS. Finally relays data between sockets and optionaly displays contents using the verbose flag
Implementation
static Future<SocketConnector> serverToServer(
{InternetAddress? serverAddressA,
InternetAddress? serverAddressB,
int? serverPortA,
int? serverPortB,
bool? verbose}) async {
InternetAddress senderBindAddress;
InternetAddress receiverBindAddress;
serverPortA ??= 0;
serverPortB ??= 0;
verbose ??= false;
serverAddressA ??= InternetAddress.anyIPv4;
serverAddressB ??= InternetAddress.anyIPv4;
senderBindAddress = serverAddressA;
receiverBindAddress = serverAddressA;
//List<SocketStream> socketStreams;
SocketConnector socketStream = SocketConnector(null, null, 0, 0, null, null);
// bind the socket server to an address and port
socketStream._serverSocketA = await ServerSocket.bind(senderBindAddress, serverPortA);
// bind the socket server to an address and port
socketStream._serverSocketB = await ServerSocket.bind(receiverBindAddress, serverPortB);
// listen for sender connections to the server
socketStream._serverSocketA?.listen((
sender,
) {
_handleSingleConnection(sender, true, socketStream, verbose!);
});
// listen for receiver connections to the server
socketStream._serverSocketB?.listen((receiver) {
_handleSingleConnection(receiver, false, socketStream, verbose!);
});
return (socketStream);
}