Skip to content

Instantly share code, notes, and snippets.

@creationix creationix/echo_raw.js
Last active Dec 10, 2015

Embed
What would you like to do?
A raw TCP server using node's internal libuv bindings directly.
var TCP = process.binding('tcp_wrap').TCP;
function noop() {}
var server = new TCP();
server.bind("0.0.0.0", 3000);
server.listen(511);
server.onconnection = function (client) {
console.log("connection!", client.getsockname(), client.getpeername());
client.onread = function (buffer, offset, length) {
if (!buffer) {
client.close();
console.log("Closing");
return;
}
buffer = buffer.slice(offset, offset + length);
console.log("onread", buffer.toString());
var req = client.writeBuffer(buffer);
req.oncomplete = noop;
};
client.readStart();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.