v2026.6.4
All Bundles
Bundle Shared networking types used across all HTTP libraries: Url (parsing and construction), Response (status code, headers, body), Cookie, and WebDownloader for streaming downloads. Compile with -lib net.

SecureWebSocket

Secure web socket client

Example

client := SecureWebSocket->New(Url->New("wss://echo.websocket.org"));
if(client->Connect()) {
  client->ReadSocketText()->PrintLine();
  
  client->WriteTextSocket("Hello World!");
  client->ReadSocketText()->PrintLine();
  
  client->CloseSocket();
};

Operations

AddHeader #

Adds a HTTPS request header

method : public : AddHeader(name:String, value:String) ~ Nil

Parameters

NameTypeDescription
nameStringheader name
valueStringheader value

CloseSocket #

Closes the web socket connection

method : public : CloseSocket() ~ Nil

CloseSocket #

Closes the web socket connection

method : public : CloseSocket(reason:Int) ~ Nil

Parameters

NameTypeDescription
reasonIntreason to close socket

Connect #

Opens a connection to a web socket

method : public : Connect() ~ Bool

Return

TypeDescription
Booltrue if connected, false otherwise

Example

client := Web.HTTP.SecureWebSocket->New(Web.HTTP.Url->New("wss://echo.websocket.org"));
if(client->Connect()) {
  client->WriteSocket("Hello!");
  client->ReadSocketText()->PrintLine();  # Hello!
  client->CloseSocket();
};

EnableCookies #

Sets cookie support

method : public : EnableCookies(cookies_enabled:Bool) ~ Nil

Parameters

NameTypeDescription
cookies_enabledBooltrue if cookies are enabled, false otherwise

GetCookies #

Gets the cookies

method : public : GetCookies() ~ Vector<Cookie>

Return

TypeDescription
Vector<Cookie>vector of cookies

GetIssuer #

Gets the socket's X.509 certificate issuer name

method : public : GetIssuer() ~ String

Return

TypeDescription
Stringcertificate issuer name

GetStatusCode #

Gets the last status code

method : public : GetStatusCode() ~ Int

Return

TypeDescription
Intlast status code

GetStatusMessage #

Gets the last status message

method : public : GetStatusMessage() ~ String

Return

TypeDescription
Stringlast status message

GetSubject #

Gets the socket's X.509 certificate subject name

method : public : GetSubject() ~ String

Return

TypeDescription
Stringcertificate subject name

New # constructor

Constructor

New(url:Web.HTTP.Url, cookies_enabled:Bool)

Parameters

NameTypeDescription
urlUrlURL
cookies_enabledBooltrue if cookies are enabled, false otherwise

New # constructor

Constructor

New(url:Web.HTTP.Url)

Parameters

NameTypeDescription
urlUrlURL

PingSocket #

Pings the websocket server

method : public : PingSocket() ~ Bool

Return

TypeDescription
Booltrue if pinged, false otherwise

Example

client := Web.HTTP.SecureWebSocket->New(Web.HTTP.Url->New("wss://echo.websocket.org"));
if(client->Connect()) {
  alive := client->PingSocket();
  alive->PrintLine();   # true
  client->CloseSocket();
};

ReadSocketBinary #

Reads binary input from the web socket

method : public : ReadSocketBinary() ~ Byte[]

Return

TypeDescription
Bytebinary input read, Nil otherwise

ReadSocketText #

Reads text from the web socket

method : public : ReadSocketText() ~ String

Return

TypeDescription
Stringtext read, Nil otherwise

RemoveHeader #

Removes a HTTPS request header

method : public : RemoveHeader(name:String) ~ Nil

Parameters

NameTypeDescription
nameStringheader name

WriteSocket #

Writes binary output to the web socket

method : public : WriteSocket(data:Byte[], fragment:Bool) ~ Bool

Parameters

NameTypeDescription
dataBytebinary payload
fragmentBooltrue if fragmented, false otherwise

Return

TypeDescription
Booltrue if successful, false otherwise

Example

client := Web.HTTP.SecureWebSocket->New(Web.HTTP.Url->New("wss://echo.websocket.org"));
if(client->Connect()) {
  payload := Byte->New[4];
  payload[0] := 0xDE; payload[1] := 0xAD; payload[2] := 0xBE; payload[3] := 0xEF;
  client->WriteSocket(payload);
  echo := client->ReadSocketBinary();
  echo->ToHexString()->PrintLine();  # DEADBEEF
  client->CloseSocket();
};

WriteSocket #

Writes text to the web socket

method : public : WriteSocket(message:String, fragment:Bool) ~ Bool

Parameters

NameTypeDescription
messageStringmessage
fragmentBooltrue if fragmented, false otherwise

Return

TypeDescription
Booltrue if successful, false otherwise

Example

client := Web.HTTP.SecureWebSocket->New(Web.HTTP.Url->New("wss://echo.websocket.org"));
if(client->Connect()) {
  client->WriteSocket("ping");
  reply := client->ReadSocketText();
  reply->PrintLine();   # ping
  client->CloseSocket();
};