Skip to content

Commit d93ef6a

Browse files
[docs] Add some initialization examples in the README
1 parent 52ebe41 commit d93ef6a

File tree

1 file changed

+37
-12
lines changed

1 file changed

+37
-12
lines changed

README.md

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -129,20 +129,26 @@ These are exposed by `require('engine.io')`:
129129
- `Object`: optional, options object (see `Server#constructor` api docs below)
130130

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

135-
// create a server first, and then attach
136-
var eioServer = require('engine.io').Server();
137-
eioServer.attach(httpServer);
133+
```js
134+
var httpServer; // previously created with `http.createServer();` from node.js api.
135+
136+
// create a server first, and then attach
137+
var eioServer = require('engine.io').Server();
138+
eioServer.attach(httpServer);
139+
140+
// or call the module as a function to get `Server`
141+
var eioServer = require('engine.io')();
142+
eioServer.attach(httpServer);
138143

139-
// or call the module as a function to get `Server`
140-
var eioServer = require('engine.io')();
141-
eioServer.attach(httpServer);
144+
// immediately attach
145+
var eioServer = require('engine.io')(httpServer);
142146

143-
// immediately attach
144-
var eioServer = require('engine.io')(httpServer);
145-
```
147+
// with custom options
148+
var eioServer = require('engine.io')(httpServer, {
149+
maxHttpBufferSize: 1e3
150+
});
151+
```
146152

147153
- `listen`
148154
- Creates an `http.Server` which listens on the given port and attaches WS
@@ -155,6 +161,17 @@ These are exposed by `require('engine.io')`:
155161
- All options from `Server.attach` method, documented below.
156162
- **Additionally** See Server `constructor` below for options you can pass for creating the new Server
157163
- **Returns** `Server`
164+
165+
```js
166+
var engine = require('engine.io');
167+
var server = engine.listen(3000, {
168+
pingTimeout: 2000,
169+
pingInterval: 10000
170+
});
171+
172+
server.on('connection', /* ... */);
173+
```
174+
158175
- `attach`
159176
- Captures `upgrade` requests for a `http.Server`. In other words, makes
160177
a regular http.Server WebSocket-compatible.
@@ -166,7 +183,15 @@ These are exposed by `require('engine.io')`:
166183
- **Additionally** See Server `constructor` below for options you can pass for creating the new Server
167184
- **Returns** `Server` a new Server instance.
168185

169-
<hr><br>
186+
```js
187+
var engine = require('engine.io');
188+
var httpServer = require('http').createServer().listen(3000);
189+
var server = engine.attach(httpServer, {
190+
wsEngine: 'uws' // requires having uws as dependency
191+
});
192+
193+
server.on('connection', /* ... */);
194+
```
170195

171196
#### Server
172197

0 commit comments

Comments
 (0)