Compare commits

...

6 Commits
0.2 ... 0.2.1

Author SHA1 Message Date
Guillermo Rauch
bf9ba8c08b Fixed encoding for WebSocket (set to utf-8 per spec)
Fixed handling of chunks sent by UA
2010-04-03 18:16:19 -07:00
Guillermo Rauch
4e58204b83 Updated client 2010-04-01 19:46:02 -07:00
Guillermo Rauch
4308ba8f14 Test client updated 2010-04-01 17:45:47 -07:00
Guillermo Rauch
0e5fb040a9 JSON try/catch (fixes #3) 2010-04-01 17:45:11 -07:00
Guillermo Rauch
e62370161d Clarified what versions of Node it's been tested on 2010-03-24 17:31:57 -07:00
Dan Loewenherz
5c5b7ee0ba update Socket.IO URL to be universally accessible 2010-03-24 17:15:22 -07:00
5 changed files with 39 additions and 23 deletions

2
.gitmodules vendored
View File

@@ -3,4 +3,4 @@
url = git://github.com/visionmedia/js-oo.git
[submodule "test/client"]
path = test/client
url = git@github.com:RosePad/Socket.IO.git
url = git://github.com/RosePad/Socket.IO.git

View File

@@ -12,7 +12,7 @@ The `Socket.IO` server provides seamless supports for a variety of transports in
Requirements
------------
- Node v0.1.32+
- Node v0.1.32+ (tested with v0.1.32, v0.1.33)
- [Socket.IO client](http://github.com/RosePad/Socket.IO) to connect from the browser
How to use
@@ -191,7 +191,7 @@ Despite this extra layer, your messages are delivered unaltered to the different
## Credits
Guillermo Rauch [guillermo@rosepad.com]
Guillermo Rauch <guillermo@rosepad.com>
Special thanks to [Jonas Pfenniger](http://github.com/zimbatm) for his workaround patch to keep the HTTPConnection open after the request is successful.

View File

@@ -22,14 +22,18 @@ this.Client = Class({
},
_onMessage: function(data){
var messages = JSON.parse(data);
try {
var messages = JSON.parse(data);
} catch(e){
return this.listener.options.log('Bad message received from client ' + this.sessionId);
}
for (var i = 0, l = messages.length; i < l; i++){
this.listener._onClientMessage(messages[i], this);
}
},
_onConnect: function(req, res){
var self = this;
var self = this;
this.request = req;
this.response = res;
this.connection = this.request.connection;

View File

@@ -1,12 +1,12 @@
var Client = require('../client').Client,
url = require('url'),
sys = require('sys');
url = require('url');
this.websocket = Client.extend({
_onConnect: function(req, res){
_onConnect: function(req, res){
var self = this;
this.__super__(req, res);
this.__super__(req, res);
this.data = '';
if (this.request.headers['connection'] !== 'Upgrade'
|| this.request.headers['upgrade'] !== 'WebSocket'
@@ -20,32 +20,44 @@ this.websocket = Client.extend({
if (!('hijack' in self.connection)){
throw new Error('You have to patch Node! Please refer to the README');
}
self.connection.hijack();
self.connection.setTimeout(0);
self.connection.setEncoding('utf8');
self.connection.setNoDelay(true);
self.connection.addListener('end', function(){ self._onClose(); });
self.connection.addListener('data', function(data){
if (data[0] !== '\u0000' && data[data.length - 1] !== '\ufffd'){
self.connection.close();
} else {
self._onMessage(data.substr(1, data.length - 2));
}
});
self.connection.addListener('end', function(){ self._onClose(); });
self.connection.addListener('data', function(data){ self._handle(data); });
});
this.response.use_chunked_encoding_by_default = false;
this.response.writeHeader(101, 'Web Socket Protocol Handshake', {
this.response.writeHeader(101, 'Web Socket Protocol Handshake', {
'Upgrade': 'WebSocket',
'Connection': 'Upgrade',
'WebSocket-Origin': this.request.headers.origin,
'WebSocket-Location': 'ws://' + this.request.headers.host + this.request.url
});
this.response.flush();
});
this.response.flush();
this._payload();
},
_handle: function(data){
this.data += data;
chunks = this.data.split('\ufffd');
chunk_count = chunks.length - 1;
for (var i = 0; i < chunk_count; i++) {
chunk = chunks[i];
if (chunk[0] != '\u0000') {
this.listener.options.log('Data incorrectly framed by UA. Dropping connection');
this.connection.close();
return false;
}
this._onMessage(chunk.slice(1));
}
this.data = chunks[chunks.length - 1];
},
_verifyOrigin: function(origin){
var parts = url.parse(origin);
return this.listener.options.origins.indexOf('*:*') !== -1