2015-09-06 86 views
-2

伊夫TCP服务器客户端连接,我尝试了net.connect:重新连接TCP net.connects产量连接ECONNREFUSED

{ [Error: connect ECONNREFUSED] 
    code: 'ECONNREFUSED', 
    errno: 'ECONNREFUSED', 
    syscall: 'connect' } 

一切工作的第一次客户端连接到端口和服务器的主机。 下一次出现此错误。 为什么以及如何重新连接/修复此问题?

概念,内在逻辑不谈,这是服务器代码:

net.createServer(function serverConnection (connection) { 

      connection.write('whatver i wana write'); 

      connection.write("\n"); 

      connection.on('end', function connectionEnd() { 
       console.log("Client Connection Ended"); 
       connection.unref(); 
       connection.destroy(); 
       server.close(); 
      }); 


     connection.on('close', function connectionClose() { 
      console.log("Connection Closed"); 
      connection.unref(); 
      connection.destroy(); 
      server.close(); 
     }); 

     connection.on('error', function connectionErr (err) { 
      console.error(err); 
      server.close(); 
     }); 

    }); 
+0

服务器拒绝连接。问题不在客户端。谁知道,也许服务器正在限制IP或其他什么东西的连接数量。 – mscdex

+0

@mscdex添加了骨架代码。可以看到更新? – user2290820

回答

1

您要关闭服务器的第一个连接关闭后。当您拨打server.close()时,服务器将停止侦听新连接。

+0

感谢man.silly me – user2290820

+0

你是否熟悉这个客户端错误?:错误:此套接字已被另一方终止]代码:'EPIPE' – user2290820