Update README.md
This commit is contained in:
@@ -1,34 +1,42 @@
|
||||
# v0.15 of µWebSockets
|
||||
|
||||
v0.15 is a complete rewrite of µWS using µSockets as foundation. This leads to a much improved code base with real separation between this and that. It makes it possible to write plugins that only touches what they aim to change. Large performance improvements are inbound for small sends via better corking, and larger sends via proper streams support. SSL is supposed to be a first class citizen as well.
|
||||
µWS ("[micro](https://en.wikipedia.org/wiki/Micro-)WS") is a modern C++17 implementation of WebSockets & HTTP. It focuses on performance & memory usage and has been shown to outperform Node.js v10 some 13x (8x with SSL) while still being just as easy to work with.
|
||||
|
||||
## Focus on HTTP
|
||||
* Stage 1: Focus on nailing fundamental HTTP(S).
|
||||
* Stage 2: Better it with built-in router via `Hub::onHttpRoute` helper.
|
||||
* Stage 3: Think about chunked responses (EventSource).
|
||||
|
||||
#### Streams and helpers
|
||||
HttpSockets are proper streams in v0.15 and do scale for large sends as well as for small ones. "Streams" are in/out per-socket-callbacks for giving or storing streamed data.
|
||||
#### Build optimized WebSocket & HTTP servers & clients in no time.
|
||||
```c++
|
||||
// Swap between SSL and non-SSL with no code change
|
||||
//uWS::SSLContext c(options);
|
||||
uWS::Context c;
|
||||
uWS::App a; // or uWS::SSLApp(options) for SSL
|
||||
|
||||
// Define high-level URL routes with args
|
||||
c.route("GET", "/", [buffer](auto *s, HttpRequest *req, auto *args) {
|
||||
a.get("/", [](auto *s, auto *req, auto *args) {
|
||||
|
||||
// Chained build-up of responses
|
||||
s->writeStatus(200)->writeHeader("Hello", "World")->end(buffer, 512);
|
||||
s->writeStatus(200)->writeHeader("Hello", "World")->end(buffer, 512);
|
||||
|
||||
}).route("GET", "/wrong", [buffer](auto *s, HttpRequest *req, auto *args) {
|
||||
}).get("/largefile", [](auto *s, auto *req, auto *args) {
|
||||
|
||||
std::cout << "Wrong way!" << std::endl;
|
||||
s->write([](int offset) {
|
||||
// stream chunks of the large file
|
||||
}, fileSize);
|
||||
|
||||
}).listen("localhost", 3000, 0);
|
||||
}).post("/upload/:filename", [](auto *s, auto *req, auto *args) {
|
||||
|
||||
// Default, per-thread Hubs
|
||||
uWS::defaultHub.run();
|
||||
s->read([std::string filename = args[0]](int offset, auto chunk) {
|
||||
// stream chunks of data in to database with filename
|
||||
});
|
||||
|
||||
}).websocket("/wsApi", [](auto *protocol) {
|
||||
|
||||
protocol->onConnection([](auto *ws) {
|
||||
|
||||
// store this websocket somewhere
|
||||
|
||||
})->onMessage([](auto *ws, auto message, auto opCode) {
|
||||
|
||||
ws->send(message, opCode);
|
||||
|
||||
})->onDisconnection([]() {
|
||||
|
||||
// remove this websocket
|
||||
|
||||
});
|
||||
|
||||
}).listen("localhost", 3000, 0);
|
||||
```
|
||||
|
||||
#### HTTP router helpers
|
||||
Fast and simple routing should be added under Hub::onHttpRoute(lalala
|
||||
|
||||
Reference in New Issue
Block a user