# Engine.IO: the realtime engine
[![Build Status](https://travis-ci.org/socketio/engine.io.svg?branch=master)](http://travis-ci.org/socketio/engine.io)
[![NPM version](https://badge.fury.io/js/engine.io.svg)](http://badge.fury.io/js/engine.io)
`Engine.IO` is the implementation of transport-based
cross-browser/cross-device bi-directional communication layer for
[Socket.IO](http://github.com/socketio/socket.io).
## How to use
### Server
#### (A) Listening on a port
```js
var engine = require('engine.io');
var server = engine.listen(80);
server.on('connection', function(socket){
socket.send('utf 8 string');
socket.send(new Buffer([0, 1, 2, 3, 4, 5])); // binary data
});
```
#### (B) Intercepting requests for a http.Server
```js
var engine = require('engine.io');
var http = require('http').createServer().listen(3000);
var server = engine.attach(http);
server.on('connection', function (socket) {
socket.on('message', function(data){ });
socket.on('close', function(){ });
});
```
#### (C) Passing in requests
```js
var engine = require('engine.io');
var server = new engine.Server();
server.on('connection', function(socket){
socket.send('hi');
});
// …
httpServer.on('upgrade', function(req, socket, head){
server.handleUpgrade(req, socket, head);
});
httpServer.on('request', function(req, res){
server.handleRequest(req, res);
});
```
### Client
```html
<script src="/path/to/engine.io.js"></script>
<script>
var socket = new eio.Socket('ws://localhost/');
socket.on('open', function(){
socket.on('message', function(data){});
socket.on('close', function(){});
});
</script>
```
For more information on the client refer to the
[engine-client](http://github.com/learnboost/engine.io-client) repository.
## What features does it have?
- **Maximum reliability**. Connections are established even in the presence of:
- proxies and load balancers.
- personal firewall and antivirus software.
- for more information refer to **Goals** and **Architecture** sections
- **Minimal client size** aided by:
- lazy loading of flash transports.
- lack of redundant transports.
- **Scalable**
- load balancer friendly
- **Future proof**
- **100% Node.JS core style**
- No API sugar (left for higher level projects)
- Written in readable vanilla JavaScript
## API
### Server
<hr><br>
#### Top-level
These are exposed by `require('engine.io')`:
##### Events
- `flush`
- Called when a socket buffer is being flushed.
- **Arguments**
- `Socket`: socket being flushed
- `Array`: write buffer
- `drain`
- Called when a socket buffer is drained
- **Arguments**
- `Socket`: socket being flushed
##### Properties
- `protocol` _(Number)_: protocol revision number
- `Server`: Server class constructor
- `Socket`: Socket class constructor
- `Transport` _(Function)_: transport constructor
- `transports` _(Object)_: map of available transports
##### Methods
- `()`
- Returns a new `Server` instance. If the first argument is an `http.Server` then the
new `Server` instance will be attached to it. Otherwise, the arguments are passed
directly to the `Server` constructor.
- **Parameters**
- `http.Server`: optional, server to attach to.
- `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);
// 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);
```
- `listen`
- Creates an `http.Server` which listens on the given port and attaches WS
to it. It returns `501 Not Implemented` for regular http requests.
- **Parameters**
- `Number`: port to listen on.
- `Object`: optional, options object
- `Function`: callback for `listen`.
- **Options**
- 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`
- `attach`
- Captures `upgrade` requests for a `http.Server`. In other words, makes
a regular http.Server WebSocket-compatible.
- **Parameters**
- `http.Server`: server to attach to.
- `Object`: optional, options object
- **Options**
- 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` a new Server instance.
<hr><br>
#### Server
The main server/manager. _Inherits from EventEmitter_.
##### Events
- `connection`
- Fired when a new connection is established.
- **Arguments**
- `Socket`: a Socket object
##### Properties
**Important**: if you plan to use Engine.IO in a scalable way, please
keep in mind the properties below will only reflect the clients connected
to a single process.
- `clients` _(Object)_: hash of connected clients by id.
- `clientsCount` _(Number)_: number of connected clients.
##### Methods
- **constructor**
- Initializes the server
- **Parameters**
- `Object`: optional, options object
- **Options**
- `pingTimeout` (`Number`): how many ms without a pong packet to
consider the connection closed (`5000`)
- `pingInterval` (`Number`): how many ms before sending a new ping
packet (`25000`)
- `upgradeTimeout` (`Number`): how many ms before an uncompleted transport upgrade is cancelled (`10000`)
- `maxHttpBufferSize` (`Number`): how many bytes or characters a message
can be, before closing the session (to avoid DoS). Default
value is `10E7`.
- `allowRequest` (`Function`): A function that receives a given handshake
or upgrade request as its first parameter, and can decide whether to
continue or not. The second argument is a function that needs to be
called with the decided information: `fn(err, success)`, where
`success` is a boolean value where false means that the request is
rejected, and err is an error code.
- `transports` (`<Array> String`): transports to allow connections
to (`['polling', 'websocket']`)
- `allowUpgrades` (`Boolean`): whether to allow transport upgrades
(`true`)
- `perMessageDeflate` (`Object|Boolean`): parameters of the WebSocket permessage-deflate extension
(see [ws module](https://github.com/einaros/ws) api docs). Set to `false` to disable. (`true`)
- `threshold` (`Number`): data is compressed only if the byte size is above this value (`1024`)
- `httpCompression` (`Object|Boolean`): parameters of the http compression for the polling transports
(see [zlib](http://nodejs.org/api/zlib.html#zlib_options) api docs). Set to `false` to disable. (`true`)
- `threshold` (`Number`): data is compressed only if the byte size is above this value (`1024`)
- `cookie` (`String|Boolean`): name of the HTTP cookie that
contains the client sid to send as part of handshake response
headers. Set to `false` to not send one. (`io`)
- `cookiePath` (`String|Boolean`): path of the above `cookie`
option. If false, no path will be sent, which means browsers will only send the cookie on the engine.io attached path (`/engine.io`).
Set false to not save io cookie on all requests. (`/`)
- `cookieHttpOnly` (`Boolean`): If `true` HttpOnly io cookie cannot be accessed by client-side APIs, such as JavaScript. (`true`) _This option has no effect if `cookie` or `cookiePath` is set to `false`._
- `wsEngine` (`String`):
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
Unity3d For Socket.IO 带 Authorization Unity3d For Socket.IO 带 Authorization 使用方式 https://blog.csdn.net/nicepainkiller/article/details/80805472 使用方式 https://blog.csdn.net/nicepainkiller/article/details/80805472
资源推荐
资源详情
资源评论
收起资源包目录
Socket.IO For Unity3D (2000个子文件)
00000000000000001000000000000000 4KB
00000000000000001000000000000000 4KB
00000000000000001000000000000000 4KB
00000000000000002000000000000000 4KB
00000000000000002000000000000000 4KB
00000000000000002000000000000000 4KB
00000000000000003000000000000000 4KB
00000000000000003000000000000000 4KB
00000000000000003000000000000000 4KB
00000000000000004000000000000000 4KB
00000000000000004000000000000000 4KB
00000000000000004000000000000000 4KB
00000000000000004100000000000000 4KB
00000000000000004100000000000000 4KB
00000000000000004100000000000000 4KB
00000000000000005000000000000000 4KB
00000000000000005000000000000000 4KB
00000000000000005000000000000000 4KB
00000000000000005100000000000000 4KB
00000000000000005100000000000000 4KB
00000000000000005100000000000000 4KB
00000000000000006000000000000000 4KB
00000000000000006000000000000000 4KB
00000000000000006000000000000000 4KB
00000000000000006100000000000000 4KB
00000000000000006100000000000000 4KB
00000000000000006100000000000000 4KB
00000000000000007000000000000000 4KB
00000000000000007000000000000000 4KB
00000000000000007000000000000000 4KB
00000000000000007100000000000000 4KB
00000000000000007100000000000000 4KB
00000000000000007100000000000000 4KB
00000000000000008000000000000000 4KB
00000000000000008000000000000000 4KB
00000000000000008000000000000000 4KB
00000000000000009000000000000000 4KB
00000000000000009000000000000000 4KB
00000000000000009000000000000000 4KB
0000000000000000a000000000000000 4KB
0000000000000000a000000000000000 4KB
0000000000000000a000000000000000 4KB
0000000000000000a100000000000000 4KB
0000000000000000a100000000000000 4KB
0000000000000000a100000000000000 4KB
0000000000000000b000000000000000 4KB
0000000000000000b000000000000000 4KB
0000000000000000b000000000000000 4KB
0000000000000000c000000000000000 4KB
0000000000000000c000000000000000 4KB
0000000000000000c000000000000000 4KB
02402f9bf7e946a4fa6749872bdd33d0 9KB
02402f9bf7e946a4fa6749872bdd33d0 9KB
024d2731b29683144af3be58152d7e95 6KB
024d2731b29683144af3be58152d7e95 6KB
0305b53a1181299409eba30b39680acd 6KB
0305b53a1181299409eba30b39680acd 6KB
0508f37c785f68b4ebd94c3469b06ff3 22KB
0508f37c785f68b4ebd94c3469b06ff3 22KB
0558474268fcfc1468cd06f7474139e2 25KB
0558474268fcfc1468cd06f7474139e2 25KB
0621b4aab2236437592f1f292cb81d20 4KB
0621b4aab2236437592f1f292cb81d20 4KB
0621b4aab2236437592f1f292cb81d20 4KB
08116a1f4132d8d4e828f5348e931f30 7KB
08116a1f4132d8d4e828f5348e931f30 7KB
08eb408943fb5364c961fcdbfa42de77 4KB
08eb408943fb5364c961fcdbfa42de77 4KB
0a938d61106c4dc46832086f65d1ea92 6KB
0a938d61106c4dc46832086f65d1ea92 6KB
0ae942f060cfbc74595074d68e8e9913 4KB
0c129397f9647414c98ecb454b6c9b61 4KB
0c129397f9647414c98ecb454b6c9b61 4KB
0d3bb855445e36e479c85976fc88383a 5KB
0d3bb855445e36e479c85976fc88383a 5KB
0d3bb855445e36e479c85976fc88383a 5KB
1033e4d1da2321748a3d9bca6a7eae75 4KB
1033e4d1da2321748a3d9bca6a7eae75 4KB
10bf81265ad87424d946598c575f45a0 8.01MB
10bf81265ad87424d946598c575f45a0 8.01MB
10bf81265ad87424d946598c575f45a0 8.01MB
12fd8a0055b84bb59e84c9835a37e333 6KB
12fd8a0055b84bb59e84c9835a37e333 6KB
12fd8a0055b84bb59e84c9835a37e333 6KB
1318072092ea698488b463bebb2848ac 6KB
1318072092ea698488b463bebb2848ac 6KB
1322fd896bbb15bb6e335591b766ae62 4KB
1322fd896bbb15bb6e335591b766ae62 4KB
1322fd896bbb15bb6e335591b766ae62 4KB
144897afaafa3cc4a98db7590f012339 63KB
144897afaafa3cc4a98db7590f012339 63KB
144bc914c9257e54b99ea77e6f1714c8 7KB
144bc914c9257e54b99ea77e6f1714c8 7KB
1521934461328a04e98f127fd326e0be 5KB
1521934461328a04e98f127fd326e0be 5KB
156616d94d5d5ee4bb1788faf05804ef 13KB
156616d94d5d5ee4bb1788faf05804ef 13KB
15be9c691b85a41a39c18beeff87e21b 10KB
15be9c691b85a41a39c18beeff87e21b 10KB
15be9c691b85a41a39c18beeff87e21b 10KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
- 村口对喷2018-08-27还可吧!不过没好好看看。就是给公司前端找的。可能对他有用吧
坎大哈
- 粉丝: 8469
- 资源: 76
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功