diff --git a/lib/stomp-node.js b/lib/stomp-node.js index 68660ee..2970599 100644 --- a/lib/stomp-node.js +++ b/lib/stomp-node.js @@ -1,7 +1,8 @@ -// Generated by CoffeeScript 1.7.1 +// Generated by CoffeeScript 1.8.0 /* - Stomp Over WebSocket http://www.jmesnil.net/stomp-websocket/doc/ | Apache License V2.0 + Stomp Over WebSocket http://www.jmesnil.net/stomp-websocket/doc/ | + Apache License V2.0 Copyright (C) 2013 [Jeff Mesnil](http://jmesnil.net/) */ @@ -22,7 +23,7 @@ }; wrapTCP = function(port, host) { - var socket, ws; + var buffer, socket, ws; socket = null; ws = { url: 'tcp:// ' + host + ':' + port, @@ -42,12 +43,19 @@ socket.on('close', function(e) { return typeof ws.onclose === "function" ? ws.onclose(e) : void 0; }); + buffer = new Buffer(0); socket.on('data', function(data) { var event; + data = Buffer.concat([buffer, data]); + if ('\n' !== data.slice(-1).toString()) { + buffer = data; + return; + } event = { 'data': data.toString() }; - return ws.onmessage(event); + ws.onmessage(event); + return buffer = new Buffer(0); }); return ws; }; diff --git a/lib/stomp.js b/lib/stomp.js index 9c30356..9a552a3 100644 --- a/lib/stomp.js +++ b/lib/stomp.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.7.1 +// Generated by CoffeeScript 1.8.0 /* Stomp Over WebSocket http://www.jmesnil.net/stomp-websocket/doc/ | Apache License V2.0 diff --git a/lib/stomp.min.js b/lib/stomp.min.js index dd0b1fa..8e43654 100644 --- a/lib/stomp.min.js +++ b/lib/stomp.min.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.7.1 +// Generated by CoffeeScript 1.8.0 /* Stomp Over WebSocket http://www.jmesnil.net/stomp-websocket/doc/ | Apache License V2.0 diff --git a/src/stomp-node.coffee b/src/stomp-node.coffee index 1ba0862..c29f102 100644 --- a/src/stomp-node.coffee +++ b/src/stomp-node.coffee @@ -4,7 +4,8 @@ # or Web sockets. ### - Stomp Over WebSocket http://www.jmesnil.net/stomp-websocket/doc/ | Apache License V2.0 + Stomp Over WebSocket http://www.jmesnil.net/stomp-websocket/doc/ | + Apache License V2.0 Copyright (C) 2013 [Jeff Mesnil](http://jmesnil.net/) ### @@ -36,11 +37,18 @@ wrapTCP = (port, host) -> socket = net.connect port, host, (e) -> ws.onopen() socket.on 'error', (e) -> ws.onclose?(e) socket.on 'close', (e) -> ws.onclose?(e) + buffer = new Buffer(0) socket.on 'data', (data) -> + data = Buffer.concat([buffer, data]) + if ('\n' != data.slice(-1).toString()) + buffer = data + return + event = { 'data': data.toString() } ws.onmessage(event) + buffer = new Buffer(0) return ws diff --git a/src/stomp-node.orig.js b/src/stomp-node.orig.js index ce68ee3..5684201 100644 --- a/src/stomp-node.orig.js +++ b/src/stomp-node.orig.js @@ -31,14 +31,22 @@ var wrapTCP = function(port, host) { ws.onclose(); } }); + var buffer = new Buffer(0); socket.on('data', function(data) { + data = Buffer.concat([buffer, data]); + if ('\n' != data.slice(-1)) { + buffer = data; + return; + } + // wrap the data in an event object var event = { 'data': data.toString() }; ws.onmessage(event); + buffer = new Buffer(0); }); - + return ws; }; @@ -56,7 +64,7 @@ var wrapWS = function(url) { connection.close(); } }; - + var socket = new WebSocketClient(); socket.on('connect', function(conn) { connection = conn;