1

I write socket client-server connection. Server listens client name and if it's not avaible, server closes connection. With correct names all works. Client:

clientSocket = new Socket("192.168.1.102", 15780);
outToServer = new DataOutputStream(clientSocket.getOutputStream());
sendRequest(uName);
currentInt = 0;
updateUI();

Then I check, whether it is possible to open connection.

private void updateUI()
    {  
        if(currentInt <= 100)
        {
            if(clientSocket.isConnected())  
            {
                outServ.setText("Complete!");
                Intent i = new Intent(this, RoomClass.class);
                startActivity(i);
                mRedrawHandler.removeMessages(0);
            }
        }else{
            currentInt++;  
            mRedrawHandler.sleep(50);  
        }
    } 

And it always is connected! But server-side closed cliet port. I heard that thus it is impossible to check up, whether connection is closed. How to make it?

Leo
  • 3,003
  • 5
  • 38
  • 61

1 Answers1

2

Socket.isConnected() will return 'false' only if the Server closes properly (calling the .close() method). If you don't have control over the server socket, then uses PrintWrite.checkError()

See this post for examples:https://stackoverflow.com/a/8268497/1012381

Community
  • 1
  • 1
JScoobyCed
  • 10,203
  • 6
  • 34
  • 58