// tcp_file_client.js
var net = require("net")
var fs = require("fs");
const { EventEmitter } = require('events');
var fileName;
EventEmitter.setMaxListeners(0)
net.createServer(function (socket) {
// new connection
fileName = parseInt(Math.random() * 10000000000000);
fileName = fileName.toString(16).toUpperCase()+ ".png";
socket.write('Some string');
socket.on('data',function (data) {
fs.writeFile(fileName ,data, { flag: "a+" },( error) => {
console.log("write file error", error)
}, cb => {
console.log("write file success", cb);
}
);
socket.on('end', function (data) {
// connection closed
console.log("file transfer end once")
});
})
}).listen(4001);
转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论,也可以邮件至 ggchzzz@163.com