template<typename
TSocket>
class NNet::TWebSocket< TSocket >
Implements a WebSocket protocol layer on top of a given socket.
The TWebSocket class wraps an underlying socket (of type TSocket
) to implement the WebSocket handshake, sending, and receiving of text frames. It uses asynchronous operations (via TFuture) for I/O, and it internally maintains a reader and writer.
Overview
- Template Parameters
-
TSocket | The underlying socket type used for network communication. |
Example: Minimal WebSocket Client
#include <iostream>
#include <coroio/ws.hpp>
template<typename TSocket>
co_await ws.Connect("echo.websocket.org", "/.ws");
std::string message = "Hello, WebSocket!";
co_await ws.SendText(message);
std::string_view reply = co_await ws.ReceiveText();
std::cout << "Received: " << reply << std::endl;
co_return;
}
High-level asynchronous socket for network communication.
Definition socket.hpp:364
TWebSocket(TSocket &socket)
Constructs a WebSocket instance wrapping the provided socket.
Definition ws.hpp:68
Future type for coroutines returning a value of type T.
Definition corochain.hpp:177