parsebody: function() { var body; if (this.previewBuffer) { this.logger.debug('[%s] parsebody\n%s', this.id, hexy.hexy(this.previewBuffer)); this.icapRequest.push(this.previewBuffer); this.previewBuffer = null; } if (this.icapRequest.ieof) { this.icapRequest.push(null); this.resetState(); this.nextState(); return; } while ((body = this.readChunk()) !== null) { if (body.data) { this.logger.debug('[%s] parsebody\n%s', this.id, hexy.hexy(body.data)); this.icapRequest.push(body.data); } if (body.eof) { this.logger.debug('[%s] parsebody eof', this.id); this.icapRequest.push(null); this.icapResponse.end(); this.resetState(); this.nextState(); break; } } }
client.on('data', function(data) { console.log('DATA:'); console.log(hexy.hexy(data)); console.log('==============================='); if(data[0] == 0x60) { console.log("找个理由退出"); console.log(hexy.hexy(new Buffer("~quit\r\n"))); client.write(new Buffer("~quit\r\n")); } else { /* var buf2 = new Buffer([ 0x60, 0x00, 0x04, 0x00, 0x00, 0x04, 0x00, 0x00, // header 0x7a, 0x32, 0x00, 0x00 // one int ]); client.write(buf2); */ } });
function hexDump(buffer, width) { if (!buffer) { return "<>"; } width = width || 32; var hexy = require("hexy"); if (buffer.length > 1024) { return hexy.hexy(buffer.slice(0, 1024), {width: width, format: "twos"}) + "\n .... ( " + buffer.length + ")"; } else { return hexy.hexy(buffer, {width: width, format: "twos"}); } }
it("should read a PEM file",function(){ var certificate = crypto_utils.readCertificate('certificates/cert.pem'); if (false) { console.log(certificate.toString("hex")); console.log(certificate.toString("base64")); console.log(hexy.hexy(certificate,{width: 32})); } certificate.toString("base64").should.equal( "MIIDJTCCAo6gAwIBAgIJAKM/ZiaPpHuNMA0GCSqGSIb3DQEBBQUAMHoxCzAJBgNV" + "BAYTAkZSMQwwCgYDVQQIEwNJREYxDjAMBgNVBAcTBVBhcmlzMRIwEAYDVQQLEwlB" + "Q01FL0xBQk8xGzAZBgNVBAMTEk5vZGVPUENVQS9VQVNlcnZlcjEcMBoGCSqGSIb3"+ "DQEJARYNaW5mb0BhY21lLmNvbTAeFw0xNDExMDUyMDI3NTlaFw0xNTExMDUyMDI3"+ "NTlaMHoxCzAJBgNVBAYTAkZSMQwwCgYDVQQIEwNJREYxDjAMBgNVBAcTBVBhcmlz"+ "MRIwEAYDVQQLEwlBQ01FL0xBQk8xGzAZBgNVBAMTEk5vZGVPUENVQS9VQVNlcnZl"+ "cjEcMBoGCSqGSIb3DQEJARYNaW5mb0BhY21lLmNvbTCBnzANBgkqhkiG9w0BAQEF"+ "AAOBjQAwgYkCgYEA1U1fm62pomj2XNuEYZqBXS987Yl0u0BKFt6rwnw6seLQCSkm"+ "Vray31p5fdkYVFBVwYTYUrk3HDM4qFnsPvJbEAC95TlAAjEb5cW0Xnx9T1nMesIv"+ "ebBS3u+Dy4CHCOYff2uUY/Dem5wHI//BqbDFtlcJ2uJTfMZBIAytxllubXECAwEA"+ "AaOBsjCBrzAMBgNVHRMBAf8EAjAAMA4GA1UdDwEB/wQEAwIC9DAgBgNVHSUBAf8E"+ "FjAUBggrBgEFBQcDAQYIKwYBBQUHAwIwTwYDVR0RBEgwRocEfwAAAYYUdXJuOk5v"+ "ZGVPUENVQS1TZXJ2ZXKCCWxvY2FsaG9zdIIJMTI3LjAuMC4xghJ3d3cueW91cmRv"+ "bWFpbi50bGQwDAYDVR0OBAUEA/4CETAOBgNVHSMEBzAFgAP+AhEwDQYJKoZIhvcN"+ "AQEFBQADgYEAtbQnMTrxpAxOo8cYfuIbpjCFPKcEfsxUf55DtX5eWjR98W9eeQxh"+ "3RhbrU9y9iAqLbTtDLbhpCSKcfKjU8l/maCVKl9VhOW8t8gVaLEwYGAq1BXNrj8f"+ "Clf72F/neh0haqvQ7BB8hEtiwUQQULxdLbTFEaXGLgA12U2rGadIRv0="); });
self.sock.once("message", function(msg, rinfo) { console.log("Display got the following from " + rinfo.address); console.log(hexy(msg)); sent = true; if (callback) process.nextTick(callback); self.emit('nextPacket'); });
function messageHeaderToString(messageChunk) { var stream = new BinaryStream(messageChunk); var messageHeader = opcua.readMessageHeader(stream); var securityHeader = chooseSecurityHeader(messageHeader.msgType); var sequenceHeader = new SequenceHeader(); assert(stream.length == 8); var secureChannelId = stream.readUInt32(); securityHeader.decode(stream); sequenceHeader.decode(stream); var slice = messageChunk.slice(0,stream.length); return messageHeader.msgType + " " + messageHeader.isFinal + " length = " + messageHeader.length + " channel = " + secureChannelId + " seqNum = " + sequenceHeader.sequenceNumber + " req ID = " + sequenceHeader.requestId + " policy "+ securityHeader.securityPolicyUri + "\n\n" + hexy.hexy(slice,{width: 32}); //" hex " + slice.toString("hex"); // return _toString(securityHeader) + "\n" + _toString(sequenceHeader); }
function log(o) { if (debug && typeof (o) === "object") { console.log(hexy.hexy(o)); } else if (debug && typeof (o) === "string") { util.puts(o); } }
it('should correclty encode a produce request', function(done){ var msg = produce.encode() .correlation(1234) .client('Mr Flibble') .timeout() .topic('test') .partition(1) .messages([{key: '', value: 'Mr Flibble'}, {key: '', value: 'Fish/Cheese'}, {key: '', value: 'Cheese/Fish'}]) .end(); var expected = '00000000: 0000 0000 0000 04d2 000a 4d72 2046 6c69 .......R..Mr.Fli\n' + '00000010: 6262 6c65 0001 0000 07d0 0000 0001 0004 bble.....P......\n' + '00000020: 7465 7374 0000 0001 0000 0001 0000 006e test...........n\n' + '00000030: 0000 0000 0000 0000 0000 0018 1114 8bc6 ...............F\n' + '00000040: 0200 ffff ffff 0000 000a 4d72 2046 6c69 ..........Mr.Fli\n' + '00000050: 6262 6c65 0000 0000 0000 0000 0000 0019 bble............\n' + '00000060: 4adf 5243 0200 ffff ffff 0000 000b 4669 J_RC..........Fi\n' + '00000070: 7368 2f43 6865 6573 6500 0000 0000 0000 sh/Cheese.......\n' + '00000080: 0000 0000 198a eadf ad02 00ff ffff ff00 ......j_-.......\n' + '00000090: 0000 0b43 6865 6573 652f 4669 7368 ...Cheese/Fish\n'; assert.equal(hexy.hexy(msg), expected); done(); });
tcpRelay.listen(tcpServerInfo, function (data, telemetry) { if (program.metdata) { var t = util.format('%s:%d -> %s:%d', telemetry.src.address, telemetry.src.port, telemetry.dst.address, telemetry.dst.port); console.error('[TCP Relay] ', t); } var fromServer = telemetry.src.port === tcpServerInfo.port && telemetry.src.address === tcpServerInfo.address; if (program.outputType == 'hex') { var dataChunk = data.slice(0, Math.min(data.length, maxShowLength)); var dots = ''; if (dataChunk.length < data.length) { dots = '...'; } console.log(hexy.hexy(dataChunk) + dots); } else { var parser; if (fromServer) { parser = serverParser; } else { parser = clientParser; } parser.write(data); } });
var processData = function(buffer, info, udpServer) { var protocol = buffer.getUInt8() var code = buffer.getUInt8() switch (protocol) { case PR_ED2K: switch (code) { case OP_GLOBGETSOURCES: receive.globGetSources(buffer, info, udpServer) break case OP_GLOBGETSOURCES2: receive.globGetSources2(buffer, info, udpServer) break case OP_GLOBSERVSTATREQ: receive.globServStatReq(buffer, info, udpServer) break case OP_SERVERDESCREQ: receive.servDescReq(buffer, info, udpServer) break case OP_GLOBSEARCHREQ: receive.globSearchReq(buffer, info, udpServer) break case OP_GLOBSEARCHREQ3: receive.globSearchReq3(buffer, info, udpServer) break default: log.warn('UDP processData: unknown operation code: 0x' + code.toString(16)) } break default: log.warn('UDP: Unsupported protocol 0x'+protocol.toString(16)) log.text(hexDump(buffer)) } }
function processRequest(socket, data) { switch (data.length) { case packet.identifier.login.len.GAME_SERVER_DETAILS_REQUEST: socket.write(packet.helper.getServerDetailsPacket(config.server.game.ip, config.server.game.port)); break; case packet.identifier.login.len.USER_CREDENTIALS: var credentials = packet.helper.getParsedCredentials(data, 10, 31); db.validateCredentials(credentials.username, credentials.password, function (rows) { if (rows.length == 0) { socket.write(packet.helper.getPreLoginMessagePacket('Invalid user ID/password!')); } else { redis.isAccountLoggedIn(credentials.username, function (active) { if (active) { socket.write(packet.helper.getPreLoginMessagePacket('Account already logged in!')); } else { redis.setAccountDetails(credentials.username, JSON.stringify(rows[0])); socket.write(packet.helper.getServerWelcomeMessagePacket(config.server_name)); } }); } }); break; default: console.log('Login server received unknown packet from client with length ' + data.length); console.log(hexy.hexy(data)); break; } }
it('should correctly encode a produce request', function(done){ var msg = produce.encode() .correlation(1234) .client('Mr Flibble') .timeout() .topic('test') .partition(1) .messages([{key: '', value: 'Mr Flibble'}, {key: '', value: 'Fish/Cheese'}, {key: '', value: 'Cheese/Fish'}]) .end(); var expected = '00000000: 0000 0000 0000 04d2 000a 4d72 2046 6c69 .......R..Mr.Fli\n' + '00000010: 6262 6c65 0001 0000 07d0 0000 0001 0004 bble.....P......\n' + '00000020: 7465 7374 0000 0001 0000 0001 0000 006e test...........n\n' + '00000030: 0000 0000 0000 0000 0000 0018 89f0 bb74 .............p;t\n' + '00000040: 0200 0000 0000 0000 000a 4d72 2046 6c69 ..........Mr.Fli\n' + '00000050: 6262 6c65 0000 0000 0000 0000 0000 0019 bble............\n' + '00000060: 6f28 64d3 0200 0000 0000 0000 000b 4669 o(dS..........Fi\n' + '00000070: 7368 2f43 6865 6573 6500 0000 0000 0000 sh/Cheese.......\n' + '00000080: 0000 0000 19af 1de9 3d02 0000 0000 0000 ...../.i=.......\n' + '00000090: 0000 0b43 6865 6573 652f 4669 7368 ...Cheese/Fish\n'; assert.equal(hexy.hexy(msg), expected); done(); });
function nextPacketPos(b) { console.log(hexy(b, { prefix: 'SEARCHING : ' })); if (b.length < 10) { console.log('TOO SHORT'); return -1; } for (var i = 1; i < b.length; ++i) { if (b.get(i) === 0x6c) { console.log( `possible match at ${i}`, b.get(i + 3), b.get(i + 1), b.get(i + 2), b.get(i + 8) ); if ( b.get(i + 3) === 1 && b.get(i + 1) < 5 && b.get(i + 2) < 4 && b.get(i + 8) < 9 ) return i; } } return -1; }
function hexDump(buffer, width) { if (!buffer) { return "<>"; } width = width || 32; var hexy = require("hexy"); return hexy.hexy(buffer, { width: width, format: "twos"}); }
it('should correctly encode a syncGroup request with assignments', function (done) { var msg = syncGroup.encode() .correlation(123) .client('test-client') .group('test-group') .generation(2) .member('test-client-member-id') .groupAssignment([ { id: 'test-client-member-id', memberAssignment: { version: 0, assignments: [ { topic: "babaganush", partitions: [1, 2] }, { topic: "fishlips", partitions: [1, 2] } ], userData: '' } }, { id: 'test-client-member-id-2', memberAssignment: { version: 0, assignments: [ { topic: "fishlips", partitions: [3] } ], userData: '' } } ]) .end(); var expected = '00000000: 000e 0000 0000 007b 000b 7465 7374 2d63 .......{..test-c\n' + '00000010: 6c69 656e 7400 0a74 6573 742d 6772 6f75 lient..test-grou\n' + '00000020: 7000 0000 0200 1574 6573 742d 636c 6965 p......test-clie\n' + '00000030: 6e74 2d6d 656d 6265 722d 6964 0000 0002 nt-member-id....\n' + '00000040: 0015 7465 7374 2d63 6c69 656e 742d 6d65 ..test-client-me\n' + '00000050: 6d62 6572 2d69 6400 0000 3800 0000 0000 mber-id...8.....\n' + '00000060: 0200 0a62 6162 6167 616e 7573 6800 0000 ...babaganush...\n' + '00000070: 0200 0000 0100 0000 0200 0866 6973 686c ...........fishl\n' + '00000080: 6970 7300 0000 0200 0000 0100 0000 0200 ips.............\n' + '00000090: 0000 0000 1774 6573 742d 636c 6965 6e74 .....test-client\n' + '000000a0: 2d6d 656d 6265 722d 6964 2d32 0000 001c -member-id-2....\n' + '000000b0: 0000 0000 0001 0008 6669 7368 6c69 7073 ........fishlips\n' + '000000c0: 0000 0001 0000 0003 0000 0000 ............\n'; assert.equal(hexy.hexy(msg), expected); done(); });
function readPacket(offset, data) { if (offset > data.length) return; console.log(' ======********====== START : ', offset, data.length); console.log( hexy(data.slice(offset, offset + 48 * 8), { prefix: 'BODY BODY: ' }) ); console.log(nextPacketPos(data.slice(offset, offset + 400))); process.exit(0); var len = data.readUInt32LE(offset); var packet; if (len > 100000) { packet = data.slice(offset, data.length); console.log(hexy(packet, { prefix: 'packet: ' })); } else { console.log('SLICING:', len, offset + 4, offset + len + 4); packet = data.slice(offset + 4, offset + len + 4); console.log(hexy(packet, { prefix: 'packet: ' })); } var dbus = new EventEmitter(); var stream = binarystream.parse(packet); dbus.on('message', function(msg) { console.log(msg); console.log( '==================== ', data.length, offset, 4 + packet.length ); readPacket(offset + 4 + packet.length, data); }); dbus.on('header', function(msg) { console.log('header: ', msg); if (msg.signature.length > 1) { } }); message.read.call(stream, dbus); }
OPCUAClient.prototype.sendOpcUARequest = function(msgType,msg,responseClass,callback) { assert(msgType.length == 3); assert(msgType=="HEL"); this._installReceiver(["ACK","ERR"],responseClass,callback); var messageChunk = opcua.packTcpMessage(msgType,msg) verify_message_chunk(messageChunk); debugLog("CLIENT SEND " + msgType.yellow + "\n" + hexy.hexy(messageChunk,{ width: 32}).red ); this._clientSocket.write(messageChunk,function(){}); };
it('should correctly encode a heartbeat request', function(done){ var msg = heartbeat.encode() .correlation(123) .client('testClient') .group('group1') .generation(5) .member('pingpong') .end(); var expected = '00000000: 000c 0000 0000 007b 000a 7465 7374 436c .......{..testCl\n' + '00000010: 6965 6e74 0006 6772 6f75 7031 0000 0005 ient..group1....\n' + '00000020: 0008 7069 6e67 706f 6e67 ..pingpong\n' assert.equal(hexy.hexy(msg), expected); done(); });
it('should correclty encode an offset request', function(done){ var msg = offset.encode() .correlation(1234) .client('Mr Flibble') .group('Motorhead') .topic('vole-frobulation') .partition(0) .end(); var expected = '00000000: 0009 0000 0000 04d2 000a 4d72 2046 6c69 .......R..Mr.Fli\n' + '00000010: 6262 6c65 0009 4d6f 746f 7268 6561 6400 bble..Motorhead.\n' + '00000020: 0000 0100 1076 6f6c 652d 6672 6f62 756c .....vole-frobul\n' + '00000030: 6174 696f 6e00 0000 0100 0000 00 ation........\n'; assert.equal(hexy.hexy(msg), expected); done(); });
it('should correctly encode a syncGroup request with empty assignments', function (done) { var msg = syncGroup.encode() .correlation(123) .client('test-client') .group('test-group') .generation(2) .member('test-client-member-id') .groupAssignment([]) .end(); var expected = '00000000: 000e 0000 0000 007b 000b 7465 7374 2d63 .......{..test-c\n' + '00000010: 6c69 656e 7400 0a74 6573 742d 6772 6f75 lient..test-grou\n' + '00000020: 7000 0000 0200 1574 6573 742d 636c 6965 p......test-clie\n' + '00000030: 6e74 2d6d 656d 6265 722d 6964 0000 0000 nt-member-id....\n'; assert.equal(hexy.hexy(msg), expected); done(); });
udpRelay.bind(server.info, function (data, telemetry) { if (program.metdata) { var t = util.format('%s:%d -> %s:%d', telemetry.src.address, telemetry.src.port, telemetry.dst.address, telemetry.dst.port); console.error('[UDP Relay] ', t); } if (program.outputType == 'hex') { var dataChunk = data.slice(0, Math.min(data.length, maxShowLength)); var dots = ''; if (dataChunk.length < data.length) { dots = '...'; } console.log(hexy.hexy(dataChunk) + dots); } else { console.log(JSON.parse(data)); } });
it('should correclty encode a produce request with a single string', function(done){ var msg = produce.encode() .correlation(1234) .client('Mr Flibble') .timeout() .topic('test') .partition(1) .messages('oscilating badgers') .end(); var expected = '00000000: 0000 0000 0000 04d2 000a 4d72 2046 6c69 .......R..Mr.Fli\n' + '00000010: 6262 6c65 0001 0000 07d0 0000 0001 0004 bble.....P......\n' + '00000020: 7465 7374 0000 0001 0000 0001 0000 002c test...........,\n' + '00000030: 0000 0000 0000 0000 0000 0020 4eb8 7bff ............N8{.\n' + '00000040: 0200 ffff ffff 0000 0012 6f73 6369 6c61 ..........oscila\n' + '00000050: 7469 6e67 2062 6164 6765 7273 ting.badgers\n'; assert.equal(hexy.hexy(msg), expected); done(); });
it('should correctly encode a joinGroup request with subscriptions', function(done){ var msg = joinGroup.encode() .correlation(123) .client('testing') .group('test-group') .sessionTimeout(333) .member('test-group-mem-id') .subscription(['topic1', 'topic2']) .end(); var expected = '00000000: 000b 0000 0000 007b 0007 7465 7374 696e .......{..testin\n' + '00000010: 6700 0a74 6573 742d 6772 6f75 7000 0001 g..test-group...\n' + '00000020: 4d00 1174 6573 742d 6772 6f75 702d 6d65 M..test-group-me\n' + '00000030: 6d2d 6964 0008 636f 6e73 756d 6572 0000 m-id..consumer..\n' + '00000040: 0001 0005 7261 6e67 6500 0000 1a00 0000 ....range.......\n' + '00000050: 0000 0200 0674 6f70 6963 3100 0674 6f70 .....topic1..top\n' + '00000060: 6963 3200 0000 00 ic2....\n'; assert.equal(hexy.hexy(msg), expected); done(); });
self.sock.send(buf, 0, buf.length, self.port, self.address, function(err) { if (err) self.emit('nextPacket'); if (err && callback) return callback(err); else if (err) throw err; console.log("Display sent to " + self.address + ": "); console.log(hexy(buf)); // wait for response self.sock.once("message", function(msg, rinfo) { console.log("Display got the following from " + rinfo.address); console.log(hexy(msg)); sent = true; if (callback) process.nextTick(callback); self.emit('nextPacket'); }); // timeout setTimeout(function() { if (!sent) { self.sock.removeAllListeners("message"); if (resend) { retry = true; send(buf, resend, callback); } else { if (callback) process.nextTick(function(){ callback(true); // error true }); sent = true; self.emit('nextPacket'); } } }, 1000); });
it('should correclty encode a commit request', function(done){ var msg = commit.encode() .correlation(1234) .client('Mr Flibble') .group('Motorhead') .topic('vole-frobulation') .partition(0) .offset(20) .timestamp() .commitMetadata() .end(); var expected = '00000000: 0008 0000 0000 04d2 000a 4d72 2046 6c69 .......R..Mr.Fli\n' + '00000010: 6262 6c65 0009 4d6f 746f 7268 6561 6400 bble..Motorhead.\n' + '00000020: 0000 0100 1076 6f6c 652d 6672 6f62 756c .....vole-frobul\n' + '00000030: 6174 696f 6e00 0000 0100 0000 0000 0000 ation...........\n' + '00000040: 0000 0000 14ff ffff ffff ffff ff00 0a6b ...............k\n' + '00000050: 6166 6b61 6573 7175 65 afkaesque\n'; assert.equal(hexy.hexy(msg), expected); done(); });
parsepreview: function() { var body; if (!this.previewBuffer) { this.previewBuffer = new Buffer(0); } while ((body = this.readChunk()) !== null) { if (body.data) { this.previewBuffer = Buffer.concat([this.previewBuffer, body.data], this.previewBuffer.length + body.data.length); } if (body.eof) { this.icapRequest.preview = this.previewBuffer; this.parsePreview = false; this.state = states.parsebody; this.logger.debug('[%s] parsepreview\n%s', this.id, hexy.hexy(this.previewBuffer)); if (this.icapRequest.isReqMod()) { this.emitEvent('httpRequest'); } else { this.emitEvent('httpResponse'); } } } },
secure_channel.chunkSecureMessage(msgType,options,msg,function(messageChunk){ if (messageChunk) { verify_message_chunk(messageChunk); debugLog("CLIENT SEND chunk "+ chunk_number + " " + msgType.yellow + "\n" + hexy.hexy(messageChunk,{ width: 32}).red ); chunk_number += 1; self._clientSocket.write(messageChunk,function(){}); } else { // note : self._responseReceiver with call callback() for us debugLog("CLIENT SEND done."); } });
socket.addListener('data', function (data) { var buffer = new Buffer(data, 'binary'); logger.info('recieved:', hexy.hexy(buffer, hexyFormat).trim()); var responseArray = [buffer[3]]; // the fourth byte is the protocol byte var date, lng, lat, MCC, MNC, LAC, cellId, TIC, voltageLevel, GSMSignalStrength, serialNumber; switch (buffer[3]) { // find protocol case 0x01: // login break; case 0x10: // date = concoxHelpers.bufToDate(buffer.slice(4, 10)); lat = concoxHelpers.bufToPos(buffer.slice(11, 15)); lng = concoxHelpers.bufToPos(buffer.slice(15, 19)); break; case 0x12: // break; case 0x13: // status heartbeat break; case 0x16: // date = concoxHelpers.bufToDate(buffer.slice(4, 10)); lat = concoxHelpers.bufToPos(buffer.slice(11, 15)); lng = concoxHelpers.bufToPos(buffer.slice(15, 19)); break; case 0x18: // break; case 0x19: // LBS, Status info package break; } responseArray = responseArray.concat([0x00, 0x01]); // server serial number var responseLength = responseArray.length + 2; // plus 2 errorBytes responseArray = [responseLength].concat(responseArray); // add length byte var errorCheck = crc16(new Buffer(responseArray)); var errorCheckBytes = concoxHelpers.getBytes(errorCheck, 2); responseArray = [0x78, 0x78].concat(responseArray); // add start bytes responseArray = responseArray.concat(errorCheckBytes); // add error bytes responseArray = responseArray.concat([0x0D, 0x0A]); // add stop bytes var responseBuffer = new Buffer(responseArray); logger.info('response:', hexy.hexy(responseBuffer, hexyFormat).trim()); socket.write(responseBuffer); if ((lat) && (lng)) { var obj = { lat: lat, lng: lng }; if (typeof(deviceConfig.id) === 'function') { obj.id = deviceConfig.id(); } else { obj.id = parseInt(deviceConfig.id); } if (date) { obj.date = date; } logger.info('id: ' + obj.id + ' lat, lng, date: ' + lat.toFixed(4) + ' ' + lng.toFixed(4) + ' ' + date); utils.sender.write(obj); } });
_ResponseReceiver.prototype._handle_response= function(messageChunk) { var self = this; var _stream = new opcua.BinaryStream(messageChunk); var messageHeader = opcua.readMessageHeader(_stream); msgType = messageHeader.msgType; // msgType_stream._buffer.slice(0,3).toString("ascii"); debugLog("CLIENT RECEIVED " + (JSON.stringify(messageHeader)+"").yellow + "\n" + hexy.hexy(messageChunk,{ width: 32}).blue.bold); if (this._expectedMsgTypes.indexOf(msgType) == -1) { // invalid message type received var errMessage ="the incoming messageChunk with msgType " + msgType + " is invalid ! expecting "+ this._expectedMsgTypes; debugLog(("ERROR ").red +errMessage); self._callback(new Error(errMessage),null); } switch(msgType) { case "ACK": var responseClass = this._responseClass; _stream.rewind(); var response = opcua.decodeMessage(_stream,responseClass); self._terminate(); self._callback(null,response); break; case "OPN": case "CLO": case "MSG": debugLog("Adding data block to message builder"); this._messageBuilder.feed(messageChunk); break; case "ERR": debugLog("ERR packet received"); //xx this._messageBuilder.feed(messageChunk); //xx var stream = new opcua.BinaryStream(messageChunk); var errCode = _stream.readUInt32(); var reason = ec.decodeUAString(_stream); self._terminate(); self._callback(new Error("CODE 0x" + errCode.toString(16) + " : " + reason),null); break; default: self._callback(new Error(" INTERNAL ERROR "+ msgType),null); break; } };
socket.on('data', function (message) { logger.debug('received data, length=' + message.length + ', bytes=\n' + hexy.hexy(message)); });