NeoGraph 0.10.0
A C++17 Graph Agent Engine Library — LangGraph for C++
Loading...
Searching...
No Matches
neograph::async::WsClient Class Reference

Async WebSocket client. More...

#include <ws_client.h>

Public Member Functions

asio::awaitable< WsMessage > recv ()
 Block until the next application message arrives.
 
asio::awaitable< void > send_binary (std::string_view payload)
 Send a binary frame (FIN=1). Masked per §5.3.
 
asio::awaitable< void > send_close (std::uint16_t code=1000, std::string_view reason="")
 Send a close frame with the given status code and optional UTF-8 reason.
 
asio::awaitable< void > send_text (std::string_view payload)
 Send a text frame (FIN=1, no fragmentation).
 

Friends

NEOGRAPH_API asio::awaitable< std::unique_ptr< WsClient > > ws_connect (asio::any_io_executor, std::string_view, std::string_view, std::string_view, std::vector< std::pair< std::string, std::string > >, bool)
 Establish a WebSocket connection.
 

Detailed Description

Async WebSocket client.

Obtain via ws_connect; use send_* / recv on the returned instance. Destruction closes the socket unconditionally (no graceful close unless you called send_close first).

Definition at line 75 of file ws_client.h.

Member Function Documentation

◆ recv()

asio::awaitable< WsMessage > neograph::async::WsClient::recv ( )

Block until the next application message arrives.

Pings are auto-replied with pongs and consumed; close frames are echoed back and surfaced to the caller as op==Close (after which the connection is no longer usable).

Throws asio::system_error on transport failure or std::runtime_error on malformed frames (reserved bits set, masked server-to-client frame, unknown opcode).

◆ send_close()

asio::awaitable< void > neograph::async::WsClient::send_close ( std::uint16_t  code = 1000,
std::string_view  reason = "" 
)

Send a close frame with the given status code and optional UTF-8 reason.

After send_close the caller should drain recv() until it returns an op==Close frame (peer echo), then let the destructor close the socket. Calling send_close twice is a no-op.

◆ send_text()

asio::awaitable< void > neograph::async::WsClient::send_text ( std::string_view  payload)

Send a text frame (FIN=1, no fragmentation).

Payload must be valid UTF-8 per RFC 6455 §5.6 — this client does NOT validate; the caller is responsible. Masked per §5.3.

Friends And Related Symbol Documentation

◆ ws_connect

NEOGRAPH_API asio::awaitable< std::unique_ptr< WsClient > > ws_connect ( asio::any_io_executor  ,
std::string_view  ,
std::string_view  ,
std::string_view  ,
std::vector< std::pair< std::string, std::string > >  ,
bool   
)
friend

Establish a WebSocket connection.

Parameters
exExecutor hosting the connection.
hostTarget host (SNI + Host header + cert verification).
portPort string ("443", "80", etc.).
pathOrigin-form path starting with '/'. Query string allowed; fragment not.
headersExtra HTTP headers injected into the Upgrade request. Typical use: {"Authorization","Bearer sk-..."}. Do NOT set Upgrade/Connection/Sec-WebSocket-* here — the client sets those itself.
tlsUse wss:// (TLS) vs ws:// (plain TCP).

Throws asio::system_error on transport failure, std::runtime_error if the server refuses the upgrade (non-101 status or bad Accept).


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