Skip to content

Instantly share code, notes, and snippets.

@jcarroyo
Created January 24, 2016 18:19
Show Gist options
  • Save jcarroyo/03947071b716595518a3 to your computer and use it in GitHub Desktop.
Save jcarroyo/03947071b716595518a3 to your computer and use it in GitHub Desktop.
Simple demo for echo client
var net = require('net');
var client = new net.Socket();
client.connect(9090, "127.0.0.1", function(){
console.log("connected");
});
var times = 5;
var interval = setInterval(function(){
if(!times){
clearInterval(interval);
client.destroy();
return;
}
var data = "data" + Math.random();
console.log("sending data", data)
client.write(data, function(){
console.log("data sended");
times--;
})
}, 2000);
client.on('data', function(data){
console.log("data received", data.toString())
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment