Update README.md

This commit is contained in:
Alex Hultman 2019-02-11 00:13:51 +01:00 committed by GitHub
parent 16e31c4e62
commit ecc7d01b8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -21,21 +21,38 @@ npm install uNetworking/uWebSockets.js#v15.1.0
where `v15.1.0` is the particular Git tag you wanted to use. where `v15.1.0` is the particular Git tag you wanted to use.
##### In a nutshell ### In a nutshell
```javascript There are tons of [examples](examples) but here's the gist of it all:
const uWS = require('uWebSockets.js');
const port = 3000;
uWS.SSLApp({ ```javascript
/* cert, key and such specified here, or use uWS.App */ const uWS = require('../dist/uws.js');
}).get('/whatsmyuseragent', (res, req) => { const port = 9001;
res.writeHeader(
'content-type', 'text/html; charset= utf-8' const app = uWS.SSLApp({
).end( key_file_name: 'misc/key.pem',
'Your user agent is: ' + req.getHeader('user-agent') cert_file_name: 'misc/cert.pem',
); passphrase: '1234'
}).get('/*', (res, req) => { }).ws('/*', {
res.end('Wildcard route'); /* Options */
compression: 0,
maxPayloadLength: 16 * 1024 * 1024,
idleTimeout: 10,
/* Handlers */
open: (ws, req) => {
console.log('A WebSocket connected via URL: ' + req.getUrl() + '!');
},
message: (ws, message, isBinary) => {
/* Ok is false if backpressure was built up, wait for drain */
let ok = ws.send(message, isBinary);
},
drain: (ws) => {
console.log('WebSocket backpressure: ' + ws.getBufferedAmount());
},
close: (ws, code, message) => {
console.log('WebSocket closed');
}
}).any('/*', (res, req) => {
res.end('Nothing to see here!');
}).listen(port, (token) => { }).listen(port, (token) => {
if (token) { if (token) {
console.log('Listening to port ' + port); console.log('Listening to port ' + port);
@ -50,6 +67,9 @@ Proper streaming of huge data is supported over Http/Https and demonstrated with
![](misc/streaming.png) ![](misc/streaming.png)
### Pub/sub
WIP section --
### Benchmarks ### Benchmarks
Performance retention is about 65% that of the native C++ [µWebSockets](https://github.com/uNetworking/uWebSockets) v0.15. That makes it some 20x as fast as Deno and even faster than most C++-only servers, all from within a JavaScript VM. Performance retention is about 65% that of the native C++ [µWebSockets](https://github.com/uNetworking/uWebSockets) v0.15. That makes it some 20x as fast as Deno and even faster than most C++-only servers, all from within a JavaScript VM.