V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
ChinaTelecom
V2EX  ›  Java

好好的 ServerSocket 久了会自己 Close 是什么情况.......

  •  
  •   ChinaTelecom · Aug 26, 2016 · 4101 views
    This topic created in 3536 days ago, the information mentioned may be changed or developed.

    核心逻辑其实巨简单,就是

    while true:
    	try
    		socket = serverSocket.accept
    		xxxx(socket)
     		......
    	catch
    		......
    

    这样的。。然后程序跑个几小时基本没问题,然而有时更久后在有新连接进来以后 accept 居然会报 SocketClosedException 出现也没什么规律 不过有个三四次了 确认程序没有任何其他地方 close 这个 而且真关了的 ServerSocket 不是应该调用 accept 时立即爆 Exception 么 这个居然是继续阻塞着每来个新连接报一次?!

    6 replies    2016-08-27 00:13:21 +08:00
    wizarot
        1
    wizarot  
       Aug 26, 2016
    你试试增加个心跳信号来维持看看?
    可能是超时了.
    ChinaTelecom
        2
    ChinaTelecom  
    OP
       Aug 26, 2016
    @wizarot accept 的超时我还特意设成 0 了...就是无限
    Comdex
        3
    Comdex  
       Aug 26, 2016
    是不是 clientSocket 关闭了....
    chareice
        4
    chareice  
       Aug 26, 2016
    心跳包,应用层的心跳包。
    owt5008137
        5
    owt5008137  
       Aug 26, 2016 via Android
    倒是贴一下 Exception 的内容啊。看看 Message 什么的,能有调用栈更好
    leaves615
        6
    leaves615  
       Aug 27, 2016
    链路黑洞
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   792 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 20:15 · PVG 04:15 · LAX 13:15 · JFK 16:15
    ♥ Do have faith in what you're doing.