Skip to content

Instantly share code, notes, and snippets.

@jots
Created January 23, 2015 20:49
Show Gist options
  • Save jots/da2602d2f0b2e4ef1bdd to your computer and use it in GitHub Desktop.
Save jots/da2602d2f0b2e4ef1bdd to your computer and use it in GitHub Desktop.
var HOST, createServer, g, net;
net = require("net");
HOST = "127.0.0.1";
createServer = function(port) {
net.createServer(function(sock) {
sock.write("welcome! on port " + port + "\r\n");
console.log("CONNECTED: " + sock.remoteAddress + ":" + sock.remotePort);
while (true) {
sock.write("hello\r\n");
}
}).listen(port, HOST);
console.log("server listening on " + port);
};
createServer(7001);
g = net.createConnection(7001, HOST);
g.on("data", function(data) {
console.log("got " + data);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment