Java socket API: How to tell if a connection has been closed?

后端 未结 8 1449
迷失自我
迷失自我 2020-11-22 02:34

I am running into some issues with the Java socket API. I am trying to display the number of players currently connected to my game. It is easy to determine when a player h

8条回答
  •  太阳男子
    2020-11-22 02:55

    Thats how I handle it

     while(true) {
            if((receiveMessage = receiveRead.readLine()) != null ) {  
    
            System.out.println("first message same :"+receiveMessage);
            System.out.println(receiveMessage);      
    
            }
            else if(receiveRead.readLine()==null)
            {
    
            System.out.println("Client has disconected: "+sock.isClosed()); 
            System.exit(1);
             }    } 
    

    if the result.code == null

提交回复
热议问题