Last active
October 14, 2019 14:05
-
-
Save riyafa/b58b4e6d424f65634179e1cd7704585f to your computer and use it in GitHub Desktop.
Attach a Ballerina WebSocket service to a http:Listener.
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/http; | |
| import ballerina/io; | |
| listener http:Listener ep = new (9090); | |
| service wsService = @http:WebSocketServiceConfig {} service { | |
| resource function onText(http:WebSocketCaller wsEp, string text) { | |
| io:println("Sever Received: " + text); | |
| } | |
| resource function onClose(http:WebSocketCaller wsEp, int statusCode, string reason) { | |
| io:println("Connection closed"); | |
| } | |
| }; | |
| public function main() { | |
| var err = ep.__attach(wsService); | |
| if (err is error) { | |
| io:println("error in attaching service to Listener", err); | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Call the service as
var ws = new WebSocket("ws://localhost:9090");using a js client