Class TcpTransport

java.lang.Object
ai.badmonkey.agentspaces.peering.transport.TcpTransport
All Implemented Interfaces:
Transport

public final class TcpTransport extends Object implements Transport
The TCP reference transport (spec ยง5.5): length-prefixed frames over a socket, with one virtual thread per connection reading inbound frames. Addresses are host:port.
  • Constructor Details

    • TcpTransport

      public TcpTransport()
  • Method Details

    • scheme

      public String scheme()
      Description copied from interface: Transport
      Returns the transport scheme, e.g. tcp, ws, mem.
      Specified by:
      scheme in interface Transport
    • dial

      public TransportConnection dial(String address) throws IOException
      Description copied from interface: Transport
      Opens a connection to a peer address.
      Specified by:
      dial in interface Transport
      Parameters:
      address - a transport-specific address
      Returns:
      the open connection
      Throws:
      IOException - if the peer cannot be reached
    • listen

      public AutoCloseable listen(String bindAddress, Consumer<TransportConnection> onAccept) throws IOException
      Description copied from interface: Transport
      Starts listening for inbound connections.
      Specified by:
      listen in interface Transport
      Parameters:
      bindAddress - a transport-specific bind address
      onAccept - invoked for each accepted connection
      Returns:
      a handle that stops listening when closed
      Throws:
      IOException - if the address cannot be bound
    • parse

      public static InetSocketAddress parse(String address)
      Returns the local port a listener handle is bound to; helper for tests and demos.