Created
April 20, 2018 06:02
-
-
Save riyafa/527950afa97398e0ec91ce0f7bd4fd3d to your computer and use it in GitHub Desktop.
Websocket Client endpoint in main method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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