Created
January 24, 2016 18:19
-
-
Save jcarroyo/03947071b716595518a3 to your computer and use it in GitHub Desktop.
Simple demo for echo client
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 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