Gin
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
AsyncWebsocket Class Reference

Asynchronous WebSocket client with non-blocking operations. More...

#include <gin_asyncwebsocket.h>

Inherits juce::Thread.

Public Member Functions

 AsyncWebsocket (const juce::URL url, const juce::StringPairArray &customHeaders={})
 
 ~AsyncWebsocket () override
 
void connect ()
 
void disconnect ()
 
bool isConnected ()
 
void setPingInterval (int seconds)
 
void send (const juce::String &text)
 
void send (const juce::MemoryBlock &binary)
 
void sendPing ()
 

Public Attributes

std::function< void()> onConnect
 
std::function< void()> onDisconnect
 
std::function< void(const juce::String &)> onText
 
std::function< void(const juce::MemoryBlock &)> onBinary
 

Detailed Description

Asynchronous WebSocket client with non-blocking operations.

AsyncWebsocket provides a thread-safe, asynchronous interface to WebSocket connections. All network operations run on a background thread, ensuring that none of the public methods block the calling thread. All callbacks are delivered on the JUCE message thread for safe UI updates.

Key Features:

Usage: Create an AsyncWebsocket with a URL, register callback handlers, then call connect(). The connection runs asynchronously on a background thread.

AsyncWebsocket ws(juce::URL("wss://example.com/socket"));
ws.onConnect = []() {
DBG("Connected!");
};
ws.onText = [](const juce::String& message) {
DBG("Received: " + message);
};
ws.onDisconnect = []() {
DBG("Disconnected");
};
ws.connect(); // Non-blocking
ws.send("Hello, server!");
Asynchronous WebSocket client with non-blocking operations.
Definition gin_asyncwebsocket.h:62
A lightweight 2D point class for projects that don't use juce_graphics.
Definition gin_point.h:25

Thread Safety:

See also
WebSocket, SecureStreamingSocket

Constructor & Destructor Documentation

◆ AsyncWebsocket()

AsyncWebsocket::AsyncWebsocket ( const juce::URL  url,
const juce::StringPairArray &  customHeaders = {} 
)

◆ ~AsyncWebsocket()

AsyncWebsocket::~AsyncWebsocket ( )
override

Member Function Documentation

◆ connect()

void AsyncWebsocket::connect ( )

◆ disconnect()

void AsyncWebsocket::disconnect ( )

◆ isConnected()

bool AsyncWebsocket::isConnected ( )

◆ setPingInterval()

void AsyncWebsocket::setPingInterval ( int  seconds)

◆ send() [1/2]

void AsyncWebsocket::send ( const juce::String &  text)

◆ send() [2/2]

void AsyncWebsocket::send ( const juce::MemoryBlock &  binary)

◆ sendPing()

void AsyncWebsocket::sendPing ( )

Member Data Documentation

◆ onConnect

std::function<void ()> AsyncWebsocket::onConnect

◆ onDisconnect

std::function<void ()> AsyncWebsocket::onDisconnect

◆ onText

std::function<void (const juce::String&)> AsyncWebsocket::onText

◆ onBinary

std::function<void (const juce::MemoryBlock&)> AsyncWebsocket::onBinary

The documentation for this class was generated from the following file: