SocketConnector class
Typical usage is via the serverToServer, serverToSocket, socketToSocket and socketToServer methods which are different flavours of the same functionality - to relay information from one socket to another.
- Upon creation, a Timer will be created for timeout duration. The timer callback, when it executes, calls close if connections
- When an established connection is closed, close will be called if connections is empty
- New Connections are added to connections when both pendingA and pendingB have at least one entry
- When verbose is true, log messages will be logged to logger
- When logTraffic is true, socket traffic will be logged to logger
Constructors
Properties
- authTimeout → Duration
-
How long to wait for a client to authenticate its self
final
- closed → bool
-
Whether this SocketConnector is closed or not
no setter
-
connections
→ List<
Connection> -
The established Connections
final
- done → Future
-
Completes when either
no setter
- gracePeriodPassed ↔ bool
-
getter/setter pair
- hashCode → int
-
The hash code for this object.
no setterinherited
- logger ↔ IOSink
-
Where we will write anything we want to log. Defaults to stderr
getter/setter pair
- logTraffic ↔ bool
-
When true, socket traffic will be logged to logger
getter/setter pair
-
pendingA
→ List<
Side> -
A Sides which are available for pairing with the next B side connections
final
-
pendingB
→ List<
Side> -
B Sides which are available for pairing with the next A side connections
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- sideAPort → int?
-
Returns the TCP port number of
_serverSocketA
if anyno setter - sideBPort → int?
-
Returns the TCP port number of
_serverSocketB
if anyno setter - timeout → Duration
-
- Upon creation, a Timer will be created for timeout duration. The timer callback calls close if connections is empty
final - verbose ↔ bool
-
When true, log messages will be logged to logger
getter/setter pair
Methods
-
close(
) → void -
handleSingleConnection(
Side thisSide) → Future< void> - Add a Side with optional SocketAuthVerifier and DataTransformer
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
serverToServer(
{InternetAddress? addressA, int portA = 0, InternetAddress? addressB, int portB = 0, bool verbose = false, bool logTraffic = false, SocketAuthVerifier? socketAuthVerifierA, SocketAuthVerifier? socketAuthVerifierB, Duration timeout = SocketConnector.defaultTimeout, Duration authTimeout = SocketConnector.defaultTimeout, IOSink? logger, int backlog = 0}) → Future< SocketConnector> - 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 optionally displays contents using the verbose flag
-
serverToSocket(
{InternetAddress? addressA, int portA = 0, required InternetAddress addressB, required int portB, DataTransformer? transformAtoB, DataTransformer? transformBtoA, bool verbose = false, bool logTraffic = false, Duration timeout = SocketConnector.defaultTimeout, IOSink? logger, bool multi = false, dynamic onConnect(Socket socketA, Socket socketB)?, dynamic beforeJoining(Side sideA, Side sideB)?, int backlog = 0}) → Future< SocketConnector> -
- Creates socket to
portB
onaddressB
- Binds to
portA
onaddressA
- Listens for a socket connection on
portA
port and joins it to the 'B' side- If
portA
is not provided then a port is chosen by the OS.addressA
defaults to InternetAddress.anyIPv4multi
flag controls whether or not to allow multiple connections to the bound server portportA
onConnect
is called whenportA
has got a new connection and a corresponding outbound socket has been created toaddressB
:portB
and the two have been joined togetherbeforeJoining
is called whenportA
has got a new connection and a corresponding outbound socket has been created toaddressB
:portB
but before they are joined together. This allows the code which called serverToSocket to take additional steps (such as setting new transformers rather than the ones which were provided initially) - Creates socket to
-
socketToServer(
{required InternetAddress addressA, required int portA, InternetAddress? addressB, int portB = 0, DataTransformer? transformAtoB, DataTransformer? transformBtoA, bool verbose = false, bool logTraffic = false, Duration timeout = SocketConnector.defaultTimeout, IOSink? logger}) → Future< SocketConnector> -
Creates socket to
portA
onaddressA
Binds to
portB
onaddressB
Listens for a socket connection on
portB
port and joins it to the 'A' sideIf
portB
is not provided then a port is chosen by the OS.addressB
defaults to InternetAddress.anyIPv4 -
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}) → Future< SocketConnector> -
- Creates socket to
portA
onaddressA
- Creates socket to
portB
onaddressB
- Relays data between the sockets
- Creates socket to
Constants
- defaultTimeout → const Duration