Skip to content

Instantly share code, notes, and snippets.

@riyafa
Created April 20, 2018 06:02
Show Gist options
  • Select an option

  • Save riyafa/527950afa97398e0ec91ce0f7bd4fd3d to your computer and use it in GitHub Desktop.

Select an option

Save riyafa/527950afa97398e0ec91ce0f7bd4fd3d to your computer and use it in GitHub Desktop.
Websocket Client endpoint in main method
import ballerina/io;
import ballerina/http;
import ballerina/runtime;
@final string REMOTE_BACKEND_URL = "ws://localhost:15500/websocket";
boolean isComplete = false;
function main(string[] args) {
http:WebSocketClient wsClientEp;
http:WebSocketClientEndpointConfig wsConfig = {
url:REMOTE_BACKEND_URL,
callbackService:clientCallbackService
};
wsClientEp.init(wsConfig);
wsClientEp.start();
while (isComplete){
runtime:sleepCurrentWorker(100);
}
}
service<http:WebSocketClientService> clientCallbackService {
onText(endpoint wsEp, string text) {
}
onBinary(endpoint wsEp, blob data) {
}
onClose(endpoint wsEp, int statusCode, string reason) {
isComplete = true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment