Skip to content

Commit

Permalink
[docs] Add some initialization examples in the README
Browse files Browse the repository at this point in the history
  • Loading branch information
darrachequesne committed Feb 28, 2018
1 parent 52ebe41 commit d93ef6a
Showing 1 changed file with 37 additions and 12 deletions.
49 changes: 37 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,20 +129,26 @@ These are exposed by `require('engine.io')`:
- `Object`: optional, options object (see `Server#constructor` api docs below)

The following are identical ways to instantiate a server and then attach it.
```js
var httpServer; // previously created with `http.createServer();` from node.js api.

// create a server first, and then attach
var eioServer = require('engine.io').Server();
eioServer.attach(httpServer);
```js
var httpServer; // previously created with `http.createServer();` from node.js api.

// create a server first, and then attach
var eioServer = require('engine.io').Server();
eioServer.attach(httpServer);

// or call the module as a function to get `Server`
var eioServer = require('engine.io')();
eioServer.attach(httpServer);

// or call the module as a function to get `Server`
var eioServer = require('engine.io')();
eioServer.attach(httpServer);
// immediately attach
var eioServer = require('engine.io')(httpServer);

// immediately attach
var eioServer = require('engine.io')(httpServer);
```
// with custom options
var eioServer = require('engine.io')(httpServer, {
maxHttpBufferSize: 1e3
});
```

- `listen`
- Creates an `http.Server` which listens on the given port and attaches WS
Expand All @@ -155,6 +161,17 @@ These are exposed by `require('engine.io')`:
- All options from `Server.attach` method, documented below.
- **Additionally** See Server `constructor` below for options you can pass for creating the new Server
- **Returns** `Server`

```js
var engine = require('engine.io');
var server = engine.listen(3000, {
pingTimeout: 2000,
pingInterval: 10000
});

server.on('connection', /* ... */);
```

- `attach`
- Captures `upgrade` requests for a `http.Server`. In other words, makes
a regular http.Server WebSocket-compatible.
Expand All @@ -166,7 +183,15 @@ These are exposed by `require('engine.io')`:
- **Additionally** See Server `constructor` below for options you can pass for creating the new Server
- **Returns** `Server` a new Server instance.

<hr><br>
```js
var engine = require('engine.io');
var httpServer = require('http').createServer().listen(3000);
var server = engine.attach(httpServer, {
wsEngine: 'uws' // requires having uws as dependency
});

server.on('connection', /* ... */);
```

#### Server

Expand Down

0 comments on commit d93ef6a

Please sign in to comment.