1. 程式人生 > >NodeJS 建立TCP伺服器 客戶端

NodeJS 建立TCP伺服器 客戶端


var net = require("net");

var client = net.connect({port:8124},function(){
	console.log("client connected");
	client.write("world \r\n");
});


client.on("data",function(data){
	console.log(data.toString());
	client.end();
});

client.on("drain",function(){
	console.log("send data clear");
});


client.on("end",function(){
	console.log("client disconnected");
});