Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add autobahn test for websocket server

  • Loading branch information...
commit 8f77e679923bef52ce1f33dc93ff9405c4e1acfa 1 parent a7a8710
@einaros einaros authored
Showing with 35 additions and 3 deletions.
  1. +3 −0  Makefile
  2. +3 −3 lib/WebSocket.js
  3. +29 −0 test/autobahn-server.js
View
3  Makefile
@@ -22,6 +22,9 @@ integrationtest:
autobahn:
@NODE_PATH=lib node test/autobahn.js
+autobahn-server:
+ @NODE_PATH=lib node test/autobahn-server.js
+
validator:
node-waf configure build
View
6 lib/WebSocket.js
@@ -315,17 +315,17 @@ function upgrade(res, socket, upgradeHead) {
});
receiver.on('ping', function(data, flags) {
flags = flags || {};
- self.pong(data, {mask: true, binary: flags.binary === true});
+ self.pong(data, {mask: !self._isServer, binary: flags.binary === true});
self.emit('ping', data, flags);
});
receiver.on('close', function(code, data, flags) {
flags = flags || {};
- self.close(code, data, {mask: true});
+ self.close(code, data, {mask: !self._isServer});
});
receiver.on('error', function(reason, errorCode) {
// close the connection when the receiver reports a HyBi error code
if (typeof errorCode !== 'undefined') {
- self.close(errorCode, '', {mask: true});
+ self.close(errorCode, '', {mask: !self._isServer});
}
self.emit('error', reason, errorCode);
});
View
29 test/autobahn-server.js
@@ -0,0 +1,29 @@
+var WebSocketServer = require('../').Server;
+
+process.on('uncaughtException', function(err) {
+ console.log('Caught exception: ', err, err.stack);
+});
+
+process.on('SIGINT', function () {
+ try {
+ console.log('Updating reports and shutting down');
+ var ws = new WebSocket('ws://localhost:9001/updateReports?agent=ws');
+ ws.on('close', function() {
+ process.exit();
+ });
+ }
+ catch(e) {
+ process.exit();
+ }
+});
+
+var wss = new WebSocketServer({port: 8181});
+wss.on('connection', function(ws) {
+ console.log('new connection');
+ ws.on('message', function(data, flags) {
+ ws.send(flags.buffer, {binary: flags.binary === true});
+ });
+ ws.on('error', function() {
+ console.log('error', arguments);
+ })
+});
Please sign in to comment.
Something went wrong with that request. Please try again.