ballerina/tcp Ballerina library
This module provides APIs for sending/receiving messages to/from another application process (local or remote) over the connection-oriented TCP protocol.
tcp:Client is used to connect to a socket server and interact with it.
The client can send the data to the server and retrieve the data from the server.
A client can be defined by providing the
remoteHost and the
A simple client code is as follows.
tcp:Listener is used to listen to the incoming socket request. The
onConnect(tcp:Caller) remote method gets invoked when a new client is connected. The new client is represented using the
onConnect(tcp:Caller) method may return
tcp:ConnectionService can have the following remote methods
onBytes(readonly & byte data) - This remote method is invoked once the content is received from the client.
onError(readonly & tcp:Error err) - This remote method is invoked in an error situation.
onClose() - This remote method is invoked when the connection is closed.
tcp:Listener can be defined as follows:
Using the TLS protocol
The Ballerina TCP module allows the use of TLS in communication. This expects a secure socket to be set in the connection configuration as shown below.
Configuring TLS in server side
Configuring TLS in client side
Released date: about 2 months ago
Ballerina version: 2201.8.0
GraalVM compatible: Yes
Pull count: 360