最近在写个系统C做了内存库和连接池管理,NODEJS写了中间件,NODEJS发起握手,两者做SOCKET通信,发现一个TIME_WATI暴增的问题
于是: 方案一,将连接池主动CLOSE,问题依旧存在 方案二,试了官网NET这个API的各种方法,问题依旧存在
虽然可以改/ETC/SYSCTL.CONF,但是想问问各位高手有无从NODEJS作为客户端层面彻底关闭链接的方法(尽管看上去与TCP原理有些相背。。。)
TCP 192.168.8.1:3699 192.168.8.108:20001 TIME_WAIT 0 TCP 192.168.8.1:3702 192.168.8.108:20001 TIME_WAIT 0 TCP 192.168.8.1:3704 192.168.8.108:20001 TIME_WAIT 0 TCP 192.168.8.1:3705 192.168.8.108:20001 TIME_WAIT 0 TCP 192.168.8.1:3706 192.168.8.108:20001 TIME_WAIT 0 TCP 192.168.8.1:3707 192.168.8.108:20001 TIME_WAIT 0 TCP 192.168.8.1:3708 192.168.8.108:20001 TIME_WAIT 0 TCP 192.168.8.1:3709 192.168.8.108:20001 TIME_WAIT 0 TCP 192.168.8.1:3710 192.168.8.108:20001 TIME_WAIT 0 TCP 192.168.8.1:3711 192.168.8.108:20001 TIME_WAIT 0 TCP 192.168.8.1:3712 192.168.8.108:20001 TIME_WAIT 0 TCP 192.168.8.1:3713 192.168.8.108:20001 TIME_WAIT 0 TCP 192.168.8.1:3714 192.168.8.108:20001 TIME_WAIT 0 TCP 192.168.8.1:3715 192.168.8.108:20001 TIME_WAIT 0 TCP 192.168.8.1:3716 192.168.8.108:20001 TIME_WAIT 0 TCP 192.168.8.1:3717 192.168.8.108:20001 TIME_WAIT 0 TCP 192.168.8.1:3718 192.168.8.108:20001 TIME_WAIT 0 TCP 192.168.8.1:3719 192.168.8.108:20001 TIME_WAIT 0 TCP 192.168.8.1:3720 192.168.8.108:20001 TIME_WAIT 0 TCP 192.168.8.1:3721 192.168.8.108:20001 TIME_WAIT 0 TCP 192.168.8.1:3722 192.168.8.108:20001 TIME_WAIT 0 TCP 192.168.8.1:3723 192.168.8.108:20001 TIME_WAIT 0
//SERVER for(;;) { recvbytes=recv(funp->fd,req_msg,100,0); //如果没有新的数据,就关闭客户端连接 if(recvbytes<=1) { tc[funp->ttd].threadstate=0; close(funp->fd); pthread_exit(NULL);
}
bzero(res_msg,30);
strcpy(res_msg,"WELCOME TO ZACARD!!");
send(funp->fd,res_msg,sizeof(res_msg),0);
printf("HANDPID:%d,HANDTID:%lu,req_msg:%s,req_bytes:%d,res_msg:%s\n",getpid(),(unsigned int)pthread_self(),req_msg,recvbytes,res_msg);//打印收到的数据
}
tc[funp->ttd].threadstate=0;
close(funp->fd);
pthread_exit(NULL);
//CLIENT function aaa(t) { var client = net.connect( {port: 20001,host:’192.168.8.108’}, function() { client.setEncoding(‘utf8’) ; // console.log(‘client connected’); client.write(‘i’m nodejs!’+’\0’); client.on('data’, function(data) { console.log(data.toString()+t); client.end();
});
});
client.on('end’, function() { client.destroy(); // console.log(‘client disconnected’);
});
client.on('error’, function() { console.log(‘cant connect to the server’); }); }