1 | # engine.io-stream
|
2 |
|
3 | simple interface to engine.io via node streams
|
4 |
|
5 | The API is pretty much the same as [shoe](https://github.com/substack/shoe)
|
6 |
|
7 | ## Example Client
|
8 |
|
9 | ```js
|
10 | var engine = require("engine.io-stream")
|
11 |
|
12 | // attach to an engine.io server at url '/numbers'
|
13 | var stream = engine("/numbers")
|
14 |
|
15 | stream.on('data', function(data) {
|
16 | console.log(data)
|
17 | stream.write('ack')
|
18 | })
|
19 | ```
|
20 |
|
21 | ## Example Server
|
22 |
|
23 | ```js
|
24 | var http = require("http")
|
25 | var EngineServer = require("engine.io-stream")
|
26 |
|
27 | // engines need to attach to server instances (see below)
|
28 | var server = http.createServer(...)
|
29 |
|
30 | var engine = EngineServer(function(stream) {
|
31 | // send back some numbers, you know...for fun
|
32 | var iv = setInterval(function () {
|
33 | stream.write(String(Math.floor(Math.random() * 2)))
|
34 | }, 250)
|
35 |
|
36 | stream.once("end", function () {
|
37 | clearInterval(iv)
|
38 | })
|
39 |
|
40 | stream.pipe(process.stdout, { end : false })
|
41 | })
|
42 |
|
43 | // expose the engine instance at this url
|
44 | engine.attach(server, "/numbers")
|
45 |
|
46 | server.listen(8080, function() {
|
47 | console.log("Listening on port 8080")
|
48 | })
|
49 | ```
|
50 |
|
51 | ## Installation
|
52 |
|
53 | `npm install engine.io-stream`
|
54 |
|
55 | ## Contributors
|
56 |
|
57 | - Raynos
|
58 | - shtylman
|
59 | - juliangruber
|
60 | - hij1nx
|
61 |
|
62 | ## Licence
|
63 | MIT
|
64 |
|