tobyxdd
V2EX  ›  Java

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

  •  
  •   tobyxdd ·
    tobyxdd · Aug 26, 2016 · 3033 views
    This topic created in 3549 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 么 这个居然是继续阻塞着每来个新连接报一次?!

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2893 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 12:03 · PVG 20:03 · LAX 05:03 · JFK 08:03
    ♥ Do have faith in what you're doing.