server:
var net = require('net');
var socket =[];var server = net.createServer(function(c){ console.log("c:" , c.ip , c.port); socket.push(c); c.on("end" , function(){ console.log("cut close"); }) c.on("data" , function(data){ console.log("..........") socket[0].write(data.toString()); }) c.write("hello \r\n"); c.pipe(c);})server.listen("9999", function(){ console.log("listen:")})client :
var net = require('net');
var fs = require('fs'); var socket = new net.Socket({ port:9090});console.log("socket:")try{ socket.connect({port:9999 , host:"127.0.0.1"} , function(c){ socket.on('data' , function(data){ console.log("data:" , data.toString()) }) socket.write("weline.cc \r\n");})}catch(e){ console.log("e:" , e)}function read(prompt, callback) { process.stdout.write(prompt + ':'); process.stdin.resume(); process.stdin.setEncoding('utf-8'); process.stdin.on('data', function(chunk) { console.log("123") //process.stdin.pause(); console.log("***************") callback(chunk); });}var send = function(data){ console.log("write") socket.write(data);}read("hqx" , send);