The different performance of "NodeJs" CTRL + C in TCP connection under Linux platform and Windows platform

Source: Internet
Author: User

Linux Platform: CentOS release 6.5 (Final)

Windows platform: Windows 7 Ultimate Edition

The server-side code is as follows:

varNET = require ('Net');varServer =Net.createserver (function (c) {Console.log ('Client Connected:'+c.remoteaddress); C.setnodelay (true); C.on ('Data', function (data) {Console.log (data);    }); C.on ('End', function () {Console.log ('disconnected from client');    }); C.on ('Error', function (err) {Console.log (err); });}); Server.listen ({port:6200}, Function () {Console.log ('Server Bound');});

The client code is as follows:

Const NET = require (' net '); Const client = Net.connect ({port:6200, localport:6201}, function () {    //' Connect ' listener    Console.log (' connected to server! ');    Client.setnodelay (true);    For (Var i=0, i<1000; i++) {        var now = Date.now ();        while (Date.now () < now + +) {}        client.write (' Chinese ');    }}); Client.on (' Data ', (data) =>{    Console.log (data.tostring ());}); Client.on (' End ', () =>{    console.log (' Disconnected from server ');});

Running Server.js on Linux, then executing client.js on Linux and Winows, and pressing CTRL + C to terminate the process during execution, I found the server side to react differently. When the client is terminated on Linux, the server outputs "disconnected from client", and when the client is terminated on the window, the server outputs "{[Error:read Econnreset] Code: ' Econnreset ', errno: ' Econnreset ', syscall: ' Read '} (if the server side listens to the error event, the server side throws an exception and exits). Why is that? I used the tcpdump tool to listen to the server port 6200 port, found the reason.

When the CTRL + C key is pressed, the client on Linux sends a message with the fin tag to the server 16:53:59.948186 IP localhost.6201 > Localhost.lm-x: Flags [F], seq, ack 1 , win 257, options [Nop,nop,ts Val 1250056051 ECR 1250053568], length 0
When the CTRL + C key is pressed, the client on Windows sends a message with the RST token to the server 16:55:14.681005 IP localhost.6201 > Localhost.lm-x: Flags [R], seq 6007, ACK 1, win 0, length 0

Note:

1. Reset bit (RST): when rst=1 indicates a serious error in the TCP connection, the connection must be released and then re-established.

The different performance of "NodeJs" CTRL + C in TCP connection under Linux platform and Windows platform

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.