Compare commits

...

12 Commits
0.6.0 ... 0.6.1

Author SHA1 Message Date
Guillermo Rauch
3c61f64d29 Prepping package.json for npm publishing 2010-11-08 20:00:15 -03:00
Guillermo Rauch
e91c785ac8 0.6.1 changelog 2010-11-08 19:59:39 -03:00
Guillermo Rauch
d0369801a1 Restored global netserver for flashsocket
Now supporting `flashPolicyServer` option (thanks Arnout)
Tests passing with and without sudo/root user
Fixed noDelay/timeout/utf-8 for draft 76 (accidental typo)
2010-11-08 18:55:27 -03:00
Guillermo Rauch
e51b37da92 Merge branch 'master' of git://github.com/3rd-Eden/Socket.IO-node 2010-11-08 17:37:32 -03:00
Arnout Kazemier
c7bec15fa9 Close the netServer when the main http server closes, this way the event loop does not keep running.
NOTE: this is patch for node 0.2.X, this is not required for node 0.3.X
2010-11-08 21:35:42 +01:00
Guillermo Rauch
4c60ed190d Merge branch 'master' of git://github.com/3rd-Eden/Socket.IO-node 2010-11-08 17:28:19 -03:00
Arnout Kazemier
d959b96363 Fallback to try{}catch handling for node < 0.2.4 , node 0.3.X seems to capture the
errors correctly using the error event.
2010-11-08 21:25:20 +01:00
Guillermo Rauch
a9dc5e081b Merge branch 'master' of git://github.com/3rd-Eden/Socket.IO-node 2010-11-08 17:17:57 -03:00
Arnout Kazemier
c168c89f1a Added the flash policy server, it's enabled by default but can be turned off if needed.
Socket.io will automatically fallback to serving the policy file inline if server is disabled or
unable to start up.
2010-11-08 21:09:52 +01:00
Guillermo Rauch
be4c847692 Misc refactor 2010-11-02 01:13:04 -03:00
Guillermo Rauch
9649b41f25 Fixed history 2010-11-01 18:50:13 -03:00
Guillermo Rauch
6a0f80e4fc Changelog 2010-11-01 18:47:08 -03:00
8 changed files with 226 additions and 62 deletions

127
History.md Normal file
View File

@@ -0,0 +1,127 @@
0.6.0 / 2010-11-01
==================
* Make sure to only write to open transports (thanks JohnDav)
* _open is still false, so destroy the connection immediately upon websocket error
* Make sure to disconnect directly onClose if the client is not handshaked and he can't possibly reconnect
* Make sure to end and destroy connection onDisconnect (for timeouts)
* Added missing .listen() call to example. Fixes #80. Thanks @machee
* Invalid transport test completed
* Initial stab at trying to detect invalid transport responses
* Make sure to provide a default for `log` if no log key was provided (internal)
* Removed unnecessary file extension verification when serving the client
* Removed unnecessary Client check upon connection
* Added support for /socket.io/WebSocketMain.swf
* Added test for /socket.io/WebSocketMain.swf
* Client serving ETag testing
* Added htmlfile transport tests
* Added extra byte to IE iframe bytes padding
* Invalid session id test
* end() before destroy()ing the socket for non-WebSocket or non-valid Upgrade requests
* Added test for non-socket.io requests
* Simplified index.js tests
* Moved listener tests into listener.js
* Make sure to call .end() when listening on connection 'end' event
* Make sure the file descriptor is destroyed on disconnection
* Fix for websocket client tracking test
* Inline (same port) flash socket policy request.
* If the server is not run with root privileges, then the flashsocket
transport will instead listen to all new connections on the main port
for policy requests. Flash policy requests happen to both port 843 and
the destination port:
http://www.lightsphere.com/dev/articles/flash_socket_policy.html
* [websocket test] Fix sending message to client upon connecting
* [websocket test] Fix for connection and handshake test
* [client files serving] Leverage end() write() call
* [client serving] Make sure to not do a useless file lookup when file is cached
* Finished json encoding test
* Look for the heartbeat in the decoded message
* Refactored websocket transports tests to match polling/multipart helpers
* Added coverage testing to Makefile
* Added heartbeat test to multipart
* Added buffered messages test for multipart
* Added assertions for `connected` property for all the tests
* Multipart clients tracking test
* Multipart client>server message sending test
* Make sure to only close the client stream when the roundtrip is complete
* Multipart connection and handshake tests:
- Implemented HTTP client on top of net.Stream with multipart boundary parsing for testing
- Test for connection / server>client message sending
* Removed unnecessary check for this.connection (since we now access the socket through req.connection for all transports)
* Test for `duration` parameter
* Added `make example` to Makefile
* Added clients tracking test for long polling
* Added message buffering test for long polling
* Improve this.request/this.response/this.connection
* Add 'end' listener onConnect, applies to all transports
* Improved error handling onConnect
* Remove legacy `flush` calls
* Removed unnecessary closeTimeout clearing in jsonp polling
* Make sure to close on disconnect if _open = true
* Clear disconnection timeout on disconnection (double check)
* Make sure to clear closeTimeout for polling transports on close.
* Replaced empty with null in log option
* Comma first style for client serving tests
* Long polling integration tests
* Test for heartbeat message
* Added heartbeat timeout test
* Support for listener#log false
* Corrected onConnect signature to support a request and a socket, or a request and a response.
* Removed error checking for non-upgradeable sockets, since they'll be destroyed, and error handling is done onConnect
* Added tests for websocket client tracking
* Added tests for websocket message buffering
* Make sure disconnect timeout is cleared on websocket re-connect
* Updated the flash socket with error detection, and readystate detection.
* This is needed because when a error occures we close down the connection,
* and the stream will become unwriteable.
* Also changed to a single write instead of multiple writes.
* Moved error handling to onConnect to avoid messing with the http.Server global error handlers
* Do special error handling for websocket
* Clearing heartbeat interval upon closing the connection
* Added error listeners, if theses errors are not correcly caught, they will leak memory.
* This caused http://speedo.no.de/ to go up from 1mb per connection after a ECONNECTRESET message
* Added encode=UTF-8 in jsonp-polling.js and xhr-polling.js since UTF-8 is the default encoding for http.ServerResponse.write
* Replaced string.length with Buffer.byteLength in jsonp-polling.js, listener.js and xhr-polling.js because content-length header requires number of bytes and not the number of symbols in string
* Fix COR headers/requests for different ports on Safari.
* Clearing the references to request, response and connection upon disconnect.
* Every require is blocking and requiring the sys module over and over and over again just makes no sense + it hurt performance.. Not to mention.. that it's already included.
* Socket.IO-node now serves the client out of the box for easier implementation
* Memory caching and ETag support for static files
* Tests
* Simplified demo even further thanks to new static file serving
* Failing to pass an origin header would throw an exception and crash the server. Added some handling.
* .connected renamed to ._open, and adopted proper `connected` (fixes #41)
* example/client updated to latest socket.io client
* Better checking of WebSocket connections
* Better handling of SSL location (thanks @jdub)
* Fix for cross-domain websocket (fixes #42)
* Removed clients/clientsIndex and only using the index (fixes #28)
* Fixed WebSocket location header for ws/wss (Thanks @jdub, Fixes #40)
* Cross domain issues with xhr-polling addressed. Thanks Niko Kaiser (@nicokaiser)
* Added origin verification for incoming data.
* Make sure pathname is set (thanks steadicat & swarmation team)
* Fix for accessing routes that being with the namespace but are not a connection attempt. Thanks @steadicat from swarmation
* JSONP-polling support
* Graceful closing of connection for invalid websocket clients
* Make it possible to just require 'socket.io'
* Make sure to abort the connect() method upon bad upgrade / origin verification
* Support for automatic JSON encoding/decoding
* Simplified chat example to take advantage of JSON encoding/decoding
* Removed fs sync call from example
* Better `how to use`
* Make sure to send content-type text/plain to `ok` POST responses
0.6.1 / 2010-11-08
* Restored flash policy server, but with these changes:
- It's contingent on the listener flashPolicyServer option
- It's started by default if socket.io is started with root access
- It correctly closes the netserver upon all the dependent http servers being closed
- The handler for the inline request is still there regardless. This is important in the following circumstances, and has no performance hit
- The port 843 is filtered
- 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

View File

@@ -107,6 +107,13 @@ Options:
socket.io
The resource is what allows the `socket.io` server to identify incoming connections by `socket.io` clients. Make sure they're in sync.
- *flashPolicyServer*
true
Create a Flash Policy file server on port 843 ( this is restricted port and you will need to have root permission ). If you disable the FlashPolicy file server Socket.io will automatically fall back to serving the policy file inline.
- *transports*

View File

@@ -34,7 +34,13 @@ send404 = function(res){
res.end();
};
server.listen(8080);
server.listen(8080, {
transportOptions: {
'xhr-polling': {
closeTimeout: 1000 * 60 * 5
}
}
});
// socket.io, I choose you
// simplest chat application evar

View File

@@ -63,10 +63,6 @@ Client.prototype._onConnect = function(req, res){
this.connection = req.connection;
this.connection.addListener('end', function(){
if (self.connection){
self.connection.end();
self.connection.destroy();
}
self._onClose();
});
@@ -103,7 +99,6 @@ Client.prototype._payload = function(){
if (payload.length) this._write(encode(payload));
if (this.connections === 1) this.listener._onClientConnect(this);
if (this.options.timeout) this._heartbeat();
};
@@ -125,40 +120,36 @@ Client.prototype._onHeartbeat = function(h){
};
Client.prototype._onClose = function(skipDisconnect){
if (this._open){
var self = this;
if ('_heartbeatInterval' in this) clearTimeout(this._heartbeatInterval);
if ('_heartbeatTimeout' in this) clearTimeout(this._heartbeatTimeout);
this._open = false;
if (skipDisconnect !== false){
if (this.handshaked)
this._disconnectTimeout = setTimeout(function(){
self._onDisconnect();
}, this.options.closeTimeout);
else
this._onDisconnect();
}
var self = this;
if (this._heartbeatInterval) clearTimeout(this._heartbeatInterval);
if (this._heartbeatTimeout) clearTimeout(this._heartbeatTimeout);
this._open = false;
if (this.connection){
this.connection.end();
this.connection.destroy();
this.connection = null;
}
this.request = null;
this.response = null;
if (skipDisconnect !== false){
if (this.handshaked){
this._disconnectTimeout = setTimeout(function(){
self._onDisconnect();
}, this.options.closeTimeout);
} else
this._onDisconnect();
}
};
Client.prototype._onDisconnect = function(){
if (this._open) this._onClose(true);
if (this._disconnectTimeout) clearTimeout(this._disconnectTimeout);
if (this.connected){
this._writeQueue = [];
this._open = false;
this.connected = false;
this.request = null;
this.response = null;
if (this.connection){
this.connection.end();
this.connection.destroy();
this.connection = null;
}
if (this.handshaked){
this.emit('disconnect');
this.listener._onClientDisconnect(this);
}
this._writeQueue = [];
this.connected = false;
if (this.handshaked){
this.emit('disconnect');
this.listener._onClientDisconnect(this);
this.handshaked = false;
}
};

View File

@@ -20,6 +20,7 @@ var Listener = module.exports = function(server, options){
this.options({
origins: '*:*',
resource: 'socket.io',
flashPolicyServer: true,
transports: ['websocket', 'flashsocket', 'htmlfile', 'xhr-multipart', 'xhr-polling', 'jsonp-polling'],
transportOptions: {},
log: sys.log

View File

@@ -1,7 +1,7 @@
var net = require('net')
, WebSocket = require('./websocket')
, listeners = []
, netserver = null;
, netserver;
var Flashsocket = module.exports = function(){
WebSocket.apply(this, arguments);
@@ -12,25 +12,66 @@ require('sys').inherits(Flashsocket, WebSocket);
Flashsocket.httpUpgrade = true;
Flashsocket.init = function(listener){
listeners.push(listener);
listener.server.on('close', function(){
listeners.splice(listeners.indexOf(listener), 1);
if (listeners.length === 0 && netserver){
try {
netserver.close();
} catch(e){}
}
});
if (listener.options.flashPolicyServer && netserver === undefined){
netserver = net.createServer(function(socket){
socket.addListener('error', function(err){
if (socket && socket.end){
socket.end();
socket.destroy();
}
});
if(socket && socket.readyState == 'open')
socket.end(policy(listeners));
});
try {
netserver.listen(843);
} catch(e){
if (e.errno == 13)
listener.options.log('Your node instance does not have root privileges. This means that the flash XML'
+ ' policy file will be served inline instead of on port 843. This might slow down'
+ ' initial connections slightly.');
netserver = null;
}
}
// Could not listen on port 843 so policy requests will be inline
listener.server.addListener('connection', function(stream){
var flashCheck = function (data) {
// Only check the initial data
stream.removeListener('data', flashCheck);
if (data[0] === 60 && data.length == 23 && data == '<policy-file-request/>\0'){
if (stream && stream.readyState == 'open'){
var xml = policy([listener]);
stream.write(xml);
stream.end();
stream.removeListener("data", flashCheck);
if (data[0] === 60 && data.length == 23) {
if (data == '<policy-file-request/>\0') {
listener.options.log("Answering flash policy request inline");
if (stream && stream.readyState == 'open'){
var xml = policy([listener]);
stream.write(xml);
stream.end();
}
}
}
};
stream.on("data", flashCheck);
stream.on('data', flashCheck);
});
};
function policy(listeners) {
var xml = '<?xml version="1.0"?>\n<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">\n<cross-domain-policy>\n';
var xml = '<?xml version="1.0"?>\n<!DOCTYPE cross-domain-policy SYSTEM'
+ ' "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">\n<cross-domain-policy>\n';
listeners.forEach(function(l){
[].concat(l.options.origins).forEach(function(origin){

View File

@@ -19,8 +19,7 @@ WebSocket.prototype._onConnect = function(req, socket){
if (this.request.headers.upgrade !== 'WebSocket' || !this._verifyOrigin(this.request.headers.origin)){
this.listener.options.log('WebSocket connection invalid or Origin not verified');
this.connection.end();
this.connection.destroy();
this._onClose();
return false;
}
@@ -49,18 +48,17 @@ WebSocket.prototype._onConnect = function(req, socket){
'WebSocket-Location: ' + location
];
this.connection.setTimeout(0);
this.connection.setNoDelay(true);
this.connection.setEncoding('utf-8');
try {
this.connection.write(headers.concat('', '').join('\r\n'));
} catch(e){
this.connection.end();
this.connection.destroy();
this._onClose();
}
}
this.connection.setTimeout(0);
this.connection.setNoDelay(true);
this.connection.setEncoding('utf-8');
this.connection.addListener('data', function(data){
self._handle(data);
});
@@ -77,12 +75,7 @@ WebSocket.prototype._handle = function(data){
chunk = chunks[i];
if (chunk[0] !== '\u0000'){
this.listener.options.log('Data incorrectly framed by UA. Dropping connection');
if (this._open){
this._onClose();
} else {
this.connection.end();
this.connection.destroy();
}
this._onClose();
return false;
}
this._onMessage(chunk.slice(1));
@@ -105,8 +98,7 @@ WebSocket.prototype._proveReception = function(headers){
if (spaces === 0 || n % spaces !== 0){
self.listener.options.log('Invalid WebSocket key: "' + k + '". Dropping connection');
self.connection.end();
self.connection.destroy();
self._onClose();
return false;
}
@@ -124,8 +116,7 @@ WebSocket.prototype._proveReception = function(headers){
try {
this.connection.write(headers.concat('', '').join('\r\n') + md5.digest('binary'), 'binary');
} catch(e){
this.connection.end();
this.connection.destroy();
this._onClose();
}
}

View File

@@ -1,6 +1,6 @@
{ "name" : "socket.io"
, "description" : "The cross-browser WebSocket"
, "version" : "0.6.0"
, "version" : "0.6.1"
, "author" : "LearnBoost"
, "licenses" :
[ { "type" : "MIT"