diff --git a/.gitignore b/.gitignore
index 1c8f4f45ab..67419b4650 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,4 +5,7 @@ lib-cov
*.csv
*.dat
*.out
-*.pid
\ No newline at end of file
+*.pid.swp
+*.swp
+*.swo
+*.swn
diff --git a/History.md b/History.md
index 8eb0a6fc0b..265be5a129 100644
--- a/History.md
+++ b/History.md
@@ -124,4 +124,15 @@ http://www.lightsphere.com/dev/articles/flash_socket_policy.html
- Flash at some point enables us to skip 843 checking altogether
- Tests compatibility
* Fixed connection timeout, noDelay and socket encoding for draft 76 (had been accidentally moved into the `else` block)
-* Some stylistic fixes
\ No newline at end of file
+* Some stylistic fixes
+
+0.7.0 /
+
+* [DEPRECATE] onClientConnect / onClientMessage / onClientDisconnect events. Please use .on('connection', function(conn){ conn.on('message', function(){}); conn.on('disconnect', function(){}); }); instead
+* [DEPRECATE} .clientsIndex accessor. Please use .clients intead
+* Improved session id generation mechanism
+* Implemented new message encoding mechanism (read more about it in the README)
+ - Implemented message types properly
+ - Implemented new message encoder/decoder with annotations support
+* Added `tests.js` set of testing helpers
+* Added `.json()` and `.broadcastJSON()` to send and brodcast messages in JSON. For just encoding objects as json you can continue to use `.send({ your: 'object' })`, but if you wish to force the JSON encoding of other types (like Number), use `.json`
diff --git a/Makefile b/Makefile
index c925f12feb..ec7c774509 100644
--- a/Makefile
+++ b/Makefile
@@ -7,4 +7,4 @@ test-cov:
example:
node ./example/server.js
-.PHONY: example
\ No newline at end of file
+.PHONY: example
diff --git a/README.md b/README.md
index 6f98dc0d50..0afd675dbf 100644
--- a/README.md
+++ b/README.md
@@ -39,8 +39,8 @@ On the server:
server = http.createServer(function(req, res){
// your normal server code
res.writeHeader(200, {'Content-Type': 'text/html'});
- res.writeBody('
Hello world
');
- res.finish();
+ res.write('Hello world
');
+ res.end();
});
server.listen(80);
@@ -50,8 +50,8 @@ On the server:
socket.on('connection', function(client){
// new client is here!
- client.on('message', function(){ … })
- client.on('disconnect', function(){ … })
+ client.on('message', function(){ //… })
+ client.on('disconnect', function(){ //… })
});
On the client:
@@ -179,21 +179,51 @@ Methods:
## Protocol
-One of the design goals is that you should be able to implement whatever protocol you desire without `Socket.IO` getting in the way. `Socket.IO` has a minimal, unobtrusive protocol layer, consisting of two parts:
+In order to make polling transports simulate the behavior of a full-duplex WebSocket, a session protocol and a message framing mechanism are required.
-* Connection handshake
-
- This is required to simulate a full duplex socket with transports such as XHR Polling or Server-sent Events (which is a "one-way socket"). The basic idea is that the first message received from the server will be a JSON object that contains a session ID used for further communications exchanged between the client and server.
-
- The concept of session also naturally benefits a full-duplex WebSocket, in the event of an accidental disconnection and a quick reconnection. Messages that the server intends to deliver to the client are cached temporarily until reconnection.
-
- The implementation of reconnection logic (potentially with retries) is left for the user. By default, transports that are keep-alive or open all the time (like WebSocket) have a timeout of 0 if a disconnection is detected.
-
-* Message batching
+The session protocol consists of the generation of a session id that is passed to the client when the communication starts. Subsequent connections to the server within that session send that session id in the URI along with the transport type.
+
+### Message encoding
+
+ (message type)":"(content length)":"(data)","
+
+(message type) is a single digit that represents one of the known message types (described below).
- Messages are buffered in order to optimize resources. In the event of the server trying to send multiple messages while a client is temporarily disconnected (eg: xhr polling), the messages are stacked and then encoded in a lightweight way, and sent to the client whenever it becomes available.
+(content length) is the number of characters of (data)
-Despite this extra layer, the messages are delivered unaltered to the various event listeners. You can `JSON.stringify()` objects, send XML, or even plain text.
+(data) is the message
+
+ 0 = force disconnection
+ No data or annotations are sent with this message (it's thus always sent as "0:0:,")
+
+ 1 = message
+ Data format:
+ (annotations)":"(message)
+
+ Annotations are meta-information associated with a message to make the Socket.IO protocol extensible. They're conceptually similar to HTTP headers. They take this format:
+
+ [key[:value][\n key[:value][\n ...]]]
+
+ For example, when you `.send('Hello world')` within the realm `'chat'`, Socket.IO really is sending:
+
+ 1:18:r:chat:Hello world,
+
+ Two annotations are used by the Socket.IO client: `r` (for `realm`) and `j` (for automatic `json` encoding / decoding of the message).
+
+ 2 = heartbeat
+ Data format:
+ (heartbeat numeric index)
+
+ Example:
+ 2:1:0,
+ 2:1:1,
+
+ 3 = session id handshake
+ Data format:
+ (session id)
+
+ Example:
+ 3:3:253,
## Credits
@@ -224,4 +254,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/example/chat.html b/example/chat.html
index 2c4b8b6831..2ab97f1ae7 100644
--- a/example/chat.html
+++ b/example/chat.html
@@ -25,7 +25,7 @@
}
function esc(msg){
- return msg.replace(//g, '>');
+ return String(msg).replace(//g, '>');
};
var socket = new io.Socket(null, {port: 8080, rememberTransport: false});
@@ -58,4 +58,4 @@ Sample chat client