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.

Constructors

SocketConnector({bool verbose = false, bool logTraffic = false, Duration timeout = defaultTimeout, IOSink? logger})

Properties

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 any
no setter
sideBPort int?
Returns the TCP port number of _serverSocketB if any
no 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, IOSink? logger}) 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)?}) Future<SocketConnector>
  • Creates socket to portB on addressB
  • Binds to portA on addressA
  • 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.anyIPv4
  • multi flag controls whether or not to allow multiple connections to the bound server port portA
  • onConnect is called when portA has got a new connection and a corresponding outbound socket has been created to addressB:portB and the two have been joined together
  • beforeJoining is called when portA has got a new connection and a corresponding outbound socket has been created to addressB: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)
  • 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 on addressA

  • Binds to portB on addressB

  • Listens for a socket connection on portB port and joins it to the 'A' side

  • If 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 on addressA
  • Creates socket to portB on addressB
  • Relays data between the sockets
  • Constants

    defaultTimeout → const Duration