Functions of ballerina.net.ws package
public function <HandshakeConnection conn> cancelHandshake(int statusCode, string reason)
Cancel the handshake
Receiver:
Receiver Name | Data Type | Description |
---|---|---|
conn | HandshakeConnection | statusCode: Status code for closing the connection |
Parameters:
Parameter Name | Data Type | Description |
---|---|---|
statusCode | int | Status code for closing the connection |
reason | string | Reason for closing the connection |
public function <Connection conn> closeConnection(int statusCode, string reason)
Close the connection
Receiver:
Receiver Name | Data Type | Description |
---|---|---|
conn | Connection | statusCode: Status code for closing the connection |
Parameters:
Parameter Name | Data Type | Description |
---|---|---|
statusCode | int | Status code for closing the connection |
reason | string | Reason for closing the connection |
public function <Connection conn> getID() (string)
Get the ID of the WebSocket connection
Receiver:
Receiver Name | Data Type | Description |
---|---|---|
conn | Connection |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
string | string: ID of the connection |
public function <Connection conn> getNegotiatedSubProtocol() (string)
Get the Negotiated sub protocol for given connection
Receiver:
Receiver Name | Data Type | Description |
---|---|---|
conn | Connection |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
string | string: Negotiated sub protocol |
public function <Connection conn> getParentConnection() (Connection)
Get parent connection if exisits
Receiver:
Receiver Name | Data Type | Description |
---|---|---|
conn | Connection | connection which the parent connection should be retrieved |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
Connection | Connection: The parent connection if exisits else null |
public function <Connection conn> getUpgradeHeader(string key) (string)
Get a value of a header
Receiver:
Receiver Name | Data Type | Description |
---|---|---|
conn | Connection | key: Key of the header which the value should be retrieved |
Parameters:
Parameter Name | Data Type | Description |
---|---|---|
key | string | Key of the header which the value should be retrieved |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
string | string: 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 Name | Data Type | Description |
---|---|---|
conn | Connection |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
map | map<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 Name | Data Type | Description |
---|---|---|
conn | Connection |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
boolean | boolean: true if the connection is opened |
public function <Connection conn> isSecure() (boolean)
Check whether the connection is secured or not
Receiver:
Receiver Name | Data Type | Description |
---|---|---|
conn | Connection |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
boolean | boolean: true if the connection is secured |
public function <Connection conn> ping(blob data)
Ping the connection
Receiver:
Receiver Name | Data Type | Description |
---|---|---|
conn | Connection | data: Binary data which should be sent |
Parameters:
Parameter Name | Data Type | Description |
---|---|---|
data | blob | Binary data which should be sent |
public function <Connection conn> pong(blob data)
Send pong message to the connection
Receiver:
Receiver Name | Data Type | Description |
---|---|---|
conn | Connection | data: Binary data which should be sent |
Parameters:
Parameter Name | Data Type | Description |
---|---|---|
data | blob | Binary data which should be sent |
public function <Connection conn> pushBinary(blob data)
Push binary data to the connection
Receiver:
Receiver Name | Data Type | Description |
---|---|---|
conn | Connection | data: Binary data which should be sent |
Parameters:
Parameter Name | Data Type | Description |
---|---|---|
data | blob | Binary data which should be sent |
public function <Connection conn> pushText(string text)
Push text to the connection
Receiver:
Receiver Name | Data Type | Description |
---|---|---|
conn | Connection | text: Text which should be sent |
Parameters:
Parameter Name | Data Type | Description |
---|---|---|
text | string | Text 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 Name | Data Type | Description |
---|---|---|
url | string | WebSocket url for the backend |
callbackService | string | Callback service to listen to the incoming messages from the backend |
action connect(ClientConnectorConfig config)
Connect to remote endpoint
Parameters:
Parameter Name | Data Type | Description |
---|---|---|
config | ClientConnectorConfig | ClientConnectorConfig for the connection |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
Connection | Connection: New WebSocket connection for the connected backend | |
WsConnectorError | Connection: New WebSocket connection for the connected backend |
action connectWithDefault()
Connect to remote endpoint with default configuration
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
Connection | Connection: New WebSocket connection for the connected backend | |
WsConnectorError | Connection: New WebSocket connection for the connected backend |
Structs of ballerina.net.ws package
public struct BinaryFrame
Represent WebSocket binary frame in Ballerina
Fields:
Field Name | Data Type | Description |
---|---|---|
data | blob | Binary data of the frame. |
isFinalFragment | boolean | Check 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 |
---|---|---|
subProtocols | string[] | Negotiable sub protocols for the client |
parentConnectionID | string | Connection ID of the parent connection which should be bind when connecting |
customHeaders | map | Custom headers which should be sent to the server |
idleTimeoutInSeconds | int | Idle 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 Name | Data Type | Description |
---|---|---|
statusCode | int | Status code for the reason of the closure of the connection. |
reason | string | Reason to close the connection. |
public struct Connection
Represent WebSocket connection in ballerina. This include all connection oriented operations
Fields:
Field Name | Data Type | Description |
---|---|---|
attributes | map | Custom user attributes. |
public struct HandshakeConnection
Represent the details needed before the Handshake is done.
Fields:
Field Name | Data Type | Description |
---|---|---|
connectionID | string | Id of the connection. |
isSecure | boolean | True if the connection is secured. |
upgradeHeaders | map | Recieved headers in the connection upgrade. |
public struct PingFrame
Represent WebSocket ping frame in Ballerina.
Fields:
Field Name | Data Type | Description |
---|---|---|
data | blob | Data of the frame. |
public struct PongFrame
Represent WebSocket pong frame in Ballerina.
Fields:
Field Name | Data Type | Description |
---|---|---|
data | blob | Data of the frame. |
public struct TextFrame
Represent WebSocket text frame in Ballerina.
Fields:
Field Name | Data Type | Description |
---|---|---|
text | string | Text in the text frame. |
isFinalFragment | boolean | Check whether this is the final frame. True if the frame is final frame. |
public struct WsConnectorError
Error structs for WebSocket connection errors.
Fields:
Field Name | Data Type | Description |
---|---|---|
msg | string | An error message explaining about the error |
cause | error | The error that caused HttpConnectorError to get thrown |
stackTrace | StackFrame[] | 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 Name | Data Type | Description |
---|
annotation configuration
Configuration for a WebSocket service.
Attributes:
Attribute Name | Data Type | Description |
---|---|---|
basePath | string | |
subProtocols | string[] | |
host | string | |
port | int | |
wssPort | int | |
idleTimeoutInSeconds | int | |
keyStoreFile | string | |
keyStorePassword | string | |
certPassword | string |