Skip to content

Commit

Permalink
use strings for empty message part check.
Browse files Browse the repository at this point in the history
  • Loading branch information
Garrett Johnson committed Aug 16, 2012
1 parent 3b44076 commit 574a052
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/sockets/rep.js
Expand Up @@ -43,7 +43,7 @@ RepSocket.prototype.onmessage = function(sock){
var envelopes = [];

for (var i = 0; i < msg.length; ++i) {
if (0x00 === msg[i][0]) {
if ('\u0000' === String(msg[i])) {
envelopes = msg.splice(0, ++i);
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/sockets/req.js
Expand Up @@ -44,7 +44,7 @@ ReqSocket.prototype.onmessage = function(){
var self = this;
return function(msg, multipart){
if (!multipart) return debug('expected multipart');
if (0x00 !== msg[0][0]) return debug('malformed message');
if ('\u0000' != String(msg[0])) return debug('malformed message');
self.emit.apply(self, ['message'].concat(msg.slice(1)));
};
};
Expand Down
31 changes: 31 additions & 0 deletions test/test.reqrep.json.js
@@ -0,0 +1,31 @@

var ss = require('../')
, should = require('should');

var server = ss.socket('rep')
, client = ss.socket('req');

server.format('json');
client.format('json');

server.bind(3000);
client.connect(3000);

server.on('message', function(msg, reply){
msg.should.have.property('cmd', 'hello');
reply({
error: null,
result: 'thanks'
});
});

client.on('message', function(msg){
msg.should.have.property('error', null);
msg.should.have.property('result', 'thanks');
client.close();
server.close();
});

client.send({
cmd: 'hello'
});

0 comments on commit 574a052

Please sign in to comment.