Swan Lake Beta2 is here.
import ballerina/websocket;
import ballerina/io;

// A WebSocket client can be configured to communicate through WSS as well.
// To secure a client using TLS/SSL, the client needs to be configured with
// a certificate file of the listener.
// The [`websocket:ClientSecureSocket`](https://docs.central.ballerina.io/ballerina/websocket/latest/records/ClientSecureSocket) record
// provides the SSL-related configurations of the client.
websocket:Client securedEP = check new("wss://localhost:9090/foo/bar",
    secureSocket = {
        cert: "../resource/path/to/public.crt"
    }
);

public function main() returns error? {
    check securedEP->writeTextMessage("Hello, World!");
    string textMessage = check securedEP->readTextMessage();
    io:println(textMessage);
}

Client - SSL/TLS

You can use the WSS client to connect or interact with an WSS listener. Provide the websocket:ClientSecureSocket configurations to the client to initiate an WSS connection.

For more information on the underlying module, see the WebSocket module.

import ballerina/websocket;
import ballerina/io;
websocket:Client securedEP = check new("wss://localhost:9090/foo/bar",
    secureSocket = {
        cert: "../resource/path/to/public.crt"
    }
);

A WebSocket client can be configured to communicate through WSS as well. To secure a client using TLS/SSL, the client needs to be configured with a certificate file of the listener. The websocket:ClientSecureSocket record provides the SSL-related configurations of the client.

public function main() returns error? {
    check securedEP->writeTextMessage("Hello, World!");
    string textMessage = check securedEP->readTextMessage();
    io:println(textMessage);
}
# As a prerequisite, start a sample service secured with SSL.
# You may need to change the trusted certificate file path.
bal run http_client_ssl_tls.bal
Hello, World!
import ballerina/websocket;
import ballerina/io;

// A WebSocket client can be configured to communicate through WSS as well.
// To secure a client using TLS/SSL, the client needs to be configured with
// a certificate file of the listener.
// The [`websocket:ClientSecureSocket`](https://docs.central.ballerina.io/ballerina/websocket/latest/records/ClientSecureSocket) record
// provides the SSL-related configurations of the client.
websocket:Client securedEP = check new("wss://localhost:9090/foo/bar",
    secureSocket = {
        cert: "../resource/path/to/public.crt"
    }
);

public function main() returns error? {
    check securedEP->writeTextMessage("Hello, World!");
    string textMessage = check securedEP->readTextMessage();
    io:println(textMessage);
}

Client - SSL/TLS

You can use the WSS client to connect or interact with an WSS listener. Provide the websocket:ClientSecureSocket configurations to the client to initiate an WSS connection.

For more information on the underlying module, see the WebSocket module.

import ballerina/websocket;
import ballerina/io;
websocket:Client securedEP = check new("wss://localhost:9090/foo/bar",
    secureSocket = {
        cert: "../resource/path/to/public.crt"
    }
);

A WebSocket client can be configured to communicate through WSS as well. To secure a client using TLS/SSL, the client needs to be configured with a certificate file of the listener. The websocket:ClientSecureSocket record provides the SSL-related configurations of the client.

public function main() returns error? {
    check securedEP->writeTextMessage("Hello, World!");
    string textMessage = check securedEP->readTextMessage();
    io:println(textMessage);
}
# As a prerequisite, start a sample service secured with SSL.
# You may need to change the trusted certificate file path.
bal run http_client_ssl_tls.bal
Hello, World!

In the creation of Ballerina, we were inspired by so many technologies. Thank you to all that have come before us (and forgive us if we missed one): Java, Go, C, C++, D, Rust, Haskell, Kotlin, Dart, TypeScript, JavaScript, Python, Perl, Flow, Swift, Elm, RelaxNG, NPM, Crates, Maven, Gradle, Kubernetes, Docker, Envoy, Markdown, GitHub and WSO2.

Cookie Policy

This website uses cookies so that we can provide you with the best user experience. Read our Cookie Policy to find out more.

If you wish to disable cookies you can do so from your browser.

I Understand