Package Exports
- socket-peek
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (socket-peek) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
node-peek
NodeJs wrapper that peeks bytes from a given socket file descriptor
Installation
Install with npm:
$ npm install socket-peekExamples
Read bytes of the next pending datagram using FIONREAD. As it takes a pointer as a parameter, it's straightforward using a Buffer as a parameter.
var fs = require('fs');
var express = require('express');
var https = require('https');
var peek = require('bindings')('peek.node').peek;
var key = fs.readFileSync('./peek-example-key.pem');
var cert = fs.readFileSync('./peek-example-cert.pem');
var https_options = {
key: key,
cert: cert
};
var PORT = 443;
var HOST = 'localhost';
app = express();
server = https.createServer(https_options, function(req, res) {
res.writeHead(200);
res.end("Hello");
}).listen(PORT, HOST);
function toHexString(byteArray) {
return byteArray.map(function(byte) {
return ('0' + (byte & 0xFF).toString(16)).slice(-2);
}).join(' ')
}
server.on('connection', function(connection) {
var buffer = new Buffer(1000);
var ret = peek(connection._handle.fd, 1000, buffer);
console.log('New connection, fd: ' + connection._handle.fd + ', ret: ' + ret);
if (ret > 0) {
console.log('Returned bytes: ' + buffer.slice(0,ret).toString('hex'));
}
});
console.log('HTTPS Server listening on %s:%s', HOST, PORT);