Last active
June 13, 2019 08:51
-
-
Save riyafa/3f0b31ce53a75911d7ef1bc00ff43b83 to your computer and use it in GitHub Desktop.
Ballerina Websocket client in main function
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; | |
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