Skip to content

Instantly share code, notes, and snippets.

@riyafa
Created August 27, 2019 08:20
Show Gist options
  • Save riyafa/984d314ecee9600ca71925732e2023c4 to your computer and use it in GitHub Desktop.
Save riyafa/984d314ecee9600ca71925732e2023c4 to your computer and use it in GitHub Desktop.
import ballerina/http;
import ballerina/io;
import ballerina/log;
public function main() {
http:WebSocketClient wsClientEp = new("ws://localhost:9090/ws/xyz/Mawanella?age=26",
config = {callbackService: ClientService, customHeaders:{"X-name":"Riyafa"}, subProtocols:["xml"]});
var err = wsClientEp->pushText("hello");
if (err is error) {
log:printError("Error in sending text", err = err);
}
}
service ClientService =@http:WebSocketServiceConfig {} service {
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