Skip to content

Instantly share code, notes, and snippets.

@riyafa
Last active June 13, 2019 08:51
Show Gist options
  • Save riyafa/3f0b31ce53a75911d7ef1bc00ff43b83 to your computer and use it in GitHub Desktop.
Save riyafa/3f0b31ce53a75911d7ef1bc00ff43b83 to your computer and use it in GitHub Desktop.
Ballerina Websocket client in main function
import ballerina/io;
import ballerina/http;
public function main() {
http:WebSocketClient wsClientEp = new("ws://echo.websocket.org", config = {callbackService: ClientService});
checkpanic wsClientEp->pushText("hello");
}
service ClientService =@http:WebSocketServiceConfig {} service {
//This resource is triggered when a new text frame is received from the remote backend.
resource function onText(http:WebSocketClient conn, string text, boolean finalFrame) {
io:println(text);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment