Listener: Listener

Isolated

This is used for creating TCP server endpoints. A TCP server endpoint is capable of responding to remote callers. The Listener is responsible for initializing the endpoint using the provided configurations.

Constructor

Initializes the TCP listener based on the provided configurations.

1 listener Listener|error? server1 = new (8080);
init (int localPort, *ListenerConfiguration config)
  • localPort int
  • The port number of the remote service

LifeCycle Methods

attach

Binds a service to the tcp:Listener.

Methods

'start

Starts the registered service programmatically.

gracefulStop

Stops the service listener gracefully.

immediateStop

Stops the service listener immediately.

detach

Stops consuming messages and detaches the service from the tcp:Listener.

attach

function attach(Service tcpService, string[ ] | string? name) returns error?
Isolated Function

Binds a service to the tcp:Listener.

1tcp:error? result = tcpListener.attach(helloService);

Parameters

  • tcpService Service
  • Type descriptor of the service

Return Type

(error?)

() or else a tcp:Error upon failure to register the listener

'start

function 'start() returns error?
Isolated Function

Starts the registered service programmatically.

Return Type

(error?)

An error if an error occurred during the listener starting process

gracefulStop

function gracefulStop() returns error?
Isolated Function

Stops the service listener gracefully. Already-accepted requests will be served before the connection closure.

Return Type

(error?)

An error if an error occurred during the listener stopping process

immediateStop

function immediateStop() returns error?
Isolated Function

Stops the service listener immediately. It is not implemented yet.

Return Type

(error?)

An error if an error occurred during the listener stop process

detach

function detach(Service tcpService) returns error?
Isolated Function

Stops consuming messages and detaches the service from the tcp:Listener.

1tcp:error? result = tcpListener.detach(helloService);

Parameters

  • tcpService Service
  • Type descriptor of the service

Return Type

(error?)

() or else a tcp:Error upon failure to detach the service