Last active
December 10, 2015 11:49
-
-
Save creationix/4430361 to your computer and use it in GitHub Desktop.
A raw TCP server using node's internal libuv bindings directly.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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