Ballerina API Documentation

Functions of ballerina.net.ws package

public function <HandshakeConnection conn> cancelHandshake(int statusCode, string reason)

Cancels the handshake

Receiver:

Receiver NameData TypeDescription
connHandshakeConnectionA HandshakeConnection struct

Parameters:

Parameter NameData TypeDescription
statusCodeintStatus code for closing the connection
reasonstringReason for closing the connection

public function <Connection conn> closeConnection(int statusCode, string reason)

Close the connection

Receiver:

Receiver NameData TypeDescription
connConnectionA Connection struct

Parameters:

Parameter NameData TypeDescription
statusCodeintStatus code for closing the connection
reasonstringReason for closing the connection

public function <Connection conn> getID() (string)

Gets the ID of the WebSocket connection

Receiver:

Receiver NameData TypeDescription
connConnectionA Connection struct

Return Parameters:

Return VariableData TypeDescription
stringID of the connection

public function <Connection conn> getNegotiatedSubProtocol() (string)

Gets the negotiated sub protocol of the connection

Receiver:

Receiver NameData TypeDescription
connConnectionA Connection struct

Return Parameters:

Return VariableData TypeDescription
stringNegotiated sub protocol

public function <Connection conn> getParentConnection() (Connection)

Gets the parent connection if there is one

Receiver:

Receiver NameData TypeDescription
connConnectionConnection for which the parent connection should be retrieved

Return Parameters:

Return VariableData TypeDescription
ConnectionThe parent connection if it exists, else it is null

public function <Connection conn> getUpgradeHeader(string key) (string)

Gets a value of a header

Receiver:

Receiver NameData TypeDescription
connConnectionA Connection struct

Parameters:

Parameter NameData TypeDescription
keystringKey of the header for which the value should be retrieved

Return Parameters:

Return VariableData TypeDescription
stringValue of the header if it exists, else it is null

public function <Connection conn> getUpgradeHeaders() (map)

Gets a map of all the upgrade headers of the connection

Receiver:

Receiver NameData TypeDescription
connConnectionA Connection struct

Return Parameters:

Return VariableData TypeDescription
mapMap of all the headers received in the connection upgrade

public function <Connection conn> isOpen() (boolean)

Checks whether the connection is still open or not.

Receiver:

Receiver NameData TypeDescription
connConnectionA Connection struct

Return Parameters:

Return VariableData TypeDescription
booleanTrue if the connection is open

public function <Connection conn> isSecure() (boolean)

Checks whether the connection is secure or not

Receiver:

Receiver NameData TypeDescription
connConnectionA Connection struct

Return Parameters:

Return VariableData TypeDescription
booleanTrue if the connection is secure

public function <Connection conn> ping(blob data)

Ping the connection

Receiver:

Receiver NameData TypeDescription
connConnectionA Connection struct

Parameters:

Parameter NameData TypeDescription
datablobBinary data to be sent

public function <Connection conn> pong(blob data)

Send pong message to the connection

Receiver:

Receiver NameData TypeDescription
connConnectionA Connection struct

Parameters:

Parameter NameData TypeDescription
datablobBinary data to be sent

public function <Connection conn> pushBinary(blob data)

Push binary data to the connection

Receiver:

Receiver NameData TypeDescription
connConnectionA Connection struct

Parameters:

Parameter NameData TypeDescription
datablobBinary data to be sent

public function <Connection conn> pushText(string text)

Push text to the connection

Receiver:

Receiver NameData TypeDescription
connConnectionA Connection struct

Parameters:

Parameter NameData TypeDescription
textstringText to be sent


Connectors of ballerina.net.ws package

public connector WsClient (string url, string callbackService)

WebSocket client connector for connecting to a WebSocket backend

Parameters:

Parameter NameData TypeDescription
urlstringWebSocket URL for the backend
callbackServicestringCallback service to listen to the incoming messages from the backend

Actions:

action connect(ClientConnectorConfig config)

Connect to remote endpoint

Parameters:

Parameter NameData TypeDescription
configClientConnectorConfigClientConnectorConfig for the connection

Return Parameters:

Return VariableData TypeDescription
ConnectionNew WebSocket connection for the connected backend
WsConnectorError

action connectWithDefault()

Connect to remote endpoint with default configuration

Return Parameters:

Return VariableData TypeDescription
ConnectionNew WebSocket connection for the connected backend
WsConnectorError


Structs of ballerina.net.ws package

public struct BinaryFrame

Represents a WebSocket binary frame in Ballerina.

Fields:

Field Name Data Type Description
datablobBinary data of the frame
isFinalFragmentbooleanCheck whether this is the final frame. True if the frame is final frame.

public struct ClientConnectorConfig

Configuration struct for WebSocket client connection

Fields:

Field Name Data Type Description
subProtocolsstring[]Negotiable sub protocols for the client
parentConnectionIDstringConnection ID of the parent connection to which it should be bound to when connecting
customHeadersmapCustom headers which should be sent to the server
idleTimeoutInSecondsintIdle timeout of the client. Upon timeout, onIdleTimeout resource in the client service will be triggered (if there is one defined).

public struct CloseFrame

Represents a WebSocket close frame in Ballerina.

Fields:

Field Name Data Type Description
statusCodeintStatus code for the reason of the closure of the connection
reasonstringReason to close the connection

public struct Connection

Represents a WebSocket connection in ballerina. This include all connection oriented operations.

Fields:

Field Name Data Type Description
attributesmapCustom user attributes

public struct HandshakeConnection

Represent the details needed before the Handshake is done.

Fields:

Field Name Data Type Description
connectionIDstringID of the connection
isSecurebooleanTrue if the connection is secured
upgradeHeadersmapReceived headers in the connection upgrade

public struct PingFrame

Represents a WebSocket ping frame in Ballerina.

Fields:

Field Name Data Type Description
datablobData of the frame

public struct PongFrame

Represents a WebSocket pong frame in Ballerina.

Fields:

Field Name Data Type Description
datablobData of the frame

public struct TextFrame

Represents a WebSocket text frame in Ballerina.

Fields:

Field Name Data Type Description
textstringText in the text frame
isFinalFragmentbooleanCheck whether this is the final frame. True if the frame is final frame.

public struct WsConnectorError

Error struct for WebSocket connection errors

Fields:

Field Name Data Type Description
msgstringAn error message explaining the error
causeerrorThe error that caused HttpConnectorError to be returned
stackTraceStackFrame[]Represents the invocation stack if WsConnectorError is thrown


Annotations of ballerina.net.ws package

annotation clientService

Service annotation to mark a WS service as a client service for a WS client connector.

annotation configuration

Configuration for a WebSocket service.

Attributes:

Attribute NameData TypeDescription
basePathstring Path of the WebSocket service
subProtocolsstring[] Negotiable sub protocol by the service
hoststring Host of the service
portint Port number of the service
wssPortint WSS port number of service
idleTimeoutInSecondsint Idle timeout for the client connection. This can be triggered by putting onIdleTimeout resource in WS service.
keyStoreFilestring File path to keystore file
keyStorePasswordstring The keystore password
certPasswordstring The certificate password


Menu

  • Functions
    • <HandshakeConnection> cancelHandshake(int statusCode, string reason)
    • <Connection> closeConnection(int statusCode, string reason)
    • <Connection> getID() (string )
    • <Connection> getNegotiatedSubProtocol() (string )
    • <Connection> getParentConnection() (Connection )
    • <Connection> getUpgradeHeader(string key) (string )
    • <Connection> getUpgradeHeaders() (map )
    • <Connection> isOpen() (boolean )
    • <Connection> isSecure() (boolean )
    • <Connection> ping(blob data)
    • <Connection> pong(blob data)
    • <Connection> pushBinary(blob data)
    • <Connection> pushText(string text)
  • Connectors
    • WsClient (string url, string callbackService)
      • connect(ClientConnectorConfig config)
      • connectWithDefault()
  • Structs
    • BinaryFrame
    • ClientConnectorConfig
    • CloseFrame
    • Connection
    • HandshakeConnection
    • PingFrame
    • PongFrame
    • TextFrame
    • WsConnectorError
  • Annotations
    • clientService
    • configuration

Copyright 2017 Ballerina API Documentation