server
const net = require('net');
var server = net.createServer(function(socket) {
console.log('client connected');
socket.on('end', function() {
console.log('客户端关闭连接');
});
socket.on("data",function (data) {
console.log(data.toString())
})
// socket.write('Hello World!\r\n');
// socket.pipe(socket);
});
client
var net = require('net');
var client = net.connect({port: 8080}, function() {
console.log('连接到服务器!');
});
client.on('data', function(data) {
console.log(data.toString());
client.end();
});
client.on('end', function() {
console.log('断开与服务器的连接');
});
网友评论