Ballerina API Documentation

Functions of ballerina.net.ws package

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

Cancel the handshake

Receiver:

Receiver NameData TypeDescription
connHandshakeConnectionstatusCode: Status code for closing the connection

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
connConnectionstatusCode: Status code for closing the connection

Parameters:

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

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

Get the ID of the WebSocket connection

Receiver:

Receiver NameData TypeDescription
connConnection

Return Parameters:

Return VariableData TypeDescription
stringstring: ID of the connection

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

Get the Negotiated sub protocol for given connection

Receiver:

Receiver NameData TypeDescription
connConnection

Return Parameters:

Return VariableData TypeDescription
stringstring: Negotiated sub protocol

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

Get parent connection if exisits

Receiver:

Receiver NameData TypeDescription
connConnectionconnection which the parent connection should be retrieved

Return Parameters:

Return VariableData TypeDescription
ConnectionConnection: The parent connection if exisits else null

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

Get a value of a header

Receiver:

Receiver NameData TypeDescription
connConnectionkey: Key of the header which the value should be retrieved

Parameters:

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

Return Parameters:

Return VariableData TypeDescription
stringstring: Value of the key if exists else null

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

Get a map of all the upgrade headers of the connection

Receiver:

Receiver NameData TypeDescription
connConnection

Return Parameters:

Return VariableData TypeDescription
mapmap<string>: Map of all the headers received in the connection upgrade

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

Check whether the connection is still open or not.

Receiver:

Receiver NameData TypeDescription
connConnection

Return Parameters:

Return VariableData TypeDescription
booleanboolean: true if the connection is opened

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

Check whether the connection is secured or not

Receiver:

Receiver NameData TypeDescription
connConnection

Return Parameters:

Return VariableData TypeDescription
booleanboolean: true if the connection is secured

public function <Connection conn> ping(blob data)

Ping the connection

Receiver:

Receiver NameData TypeDescription
connConnectiondata: Binary data which should be sent

Parameters:

Parameter NameData TypeDescription
datablobBinary data which should be sent

public function <Connection conn> pong(blob data)

Send pong message to the connection

Receiver:

Receiver NameData TypeDescription
connConnectiondata: Binary data which should be sent

Parameters:

Parameter NameData TypeDescription
datablobBinary data which should be sent

public function <Connection conn> pushBinary(blob data)

Push binary data to the connection

Receiver:

Receiver NameData TypeDescription
connConnectiondata: Binary data which should be sent

Parameters:

Parameter NameData TypeDescription
datablobBinary data which should be sent

public function <Connection conn> pushText(string text)

Push text to the connection

Receiver:

Receiver NameData TypeDescription
connConnectiontext: Text which should be sent

Parameters:

Parameter NameData TypeDescription
textstringText which should be sent


Connectors of ballerina.net.ws package

public connector WsClient (string url, string callbackService)

WebSocket client connector for connecting to 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
ConnectionConnection: New WebSocket connection for the connected backend
WsConnectorErrorConnection: New WebSocket connection for the connected backend

action connectWithDefault()

Connect to remote endpoint with default configuration

Return Parameters:

Return VariableData TypeDescription
ConnectionConnection: New WebSocket connection for the connected backend
WsConnectorErrorConnection: New WebSocket connection for the connected backend


Structs of ballerina.net.ws package

public struct BinaryFrame

Represent WebSocket binary frame in Ballerina

Fields:

Field NameData TypeDescription
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 NameData TypeDescription
subProtocolsstring[]Negotiable sub protocols for the client
parentConnectionIDstringConnection ID of the parent connection which should be bind when connecting
customHeadersmapCustom headers which should be sent to the server
idleTimeoutInSecondsintIdle timeout of the client. This can be triggered by putting onIdleTimeout resource in clinet service.

public struct CloseFrame

Represent WebSocket close frame in Ballerina.

Fields:

Field NameData TypeDescription
statusCodeintStatus code for the reason of the closure of the connection.
reasonstringReason to close the connection.

public struct Connection

Represent WebSocket connection in ballerina. This include all connection oriented operations

Fields:

Field NameData TypeDescription
attributesmapCustom user attributes.

public struct HandshakeConnection

Represent the details needed before the Handshake is done.

Fields:

Field NameData TypeDescription
connectionIDstringId of the connection.
isSecurebooleanTrue if the connection is secured.
upgradeHeadersmapRecieved headers in the connection upgrade.

public struct PingFrame

Represent WebSocket ping frame in Ballerina.

Fields:

Field NameData TypeDescription
datablobData of the frame.

public struct PongFrame

Represent WebSocket pong frame in Ballerina.

Fields:

Field NameData TypeDescription
datablobData of the frame.

public struct TextFrame

Represent WebSocket text frame in Ballerina.

Fields:

Field NameData TypeDescription
textstringText in the text frame.
isFinalFragmentbooleanCheck whether this is the final frame. True if the frame is final frame.

public struct WsConnectorError

Error structs for WebSocket connection errors.

Fields:

Field NameData TypeDescription
msgstringAn error message explaining about the error
causeerrorThe error that caused HttpConnectorError to get thrown
stackTraceStackFrame[]Represents the invocation stack when WspConnectorError 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.

Attributes:

Attribute NameData TypeDescription

annotation configuration

Configuration for a WebSocket service.

Attributes:

Attribute NameData TypeDescription
basePathstring
subProtocolsstring[]
hoststring
portint
wssPortint
idleTimeoutInSecondsint
keyStoreFilestring
keyStorePasswordstring
certPasswordstring


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()
      • connectWithDefault()
  • Structs
    • BinaryFrame
    • ClientConnectorConfig
    • CloseFrame
    • Connection
    • HandshakeConnection
    • PingFrame
    • PongFrame
    • TextFrame
    • WsConnectorError
  • Annotations
    • clientService
    • configuration

Copyright 2017 Ballerina API Documentation