How to break the connection with the java WebSocket?

In the presence of a private hand written client and server programs.

The server part is a work with sockatume.
The client part connects to this server.
In client-side code that is responsible for working with sockatume made in the service.
The service starts when the application starts.

Duplex communication works fine. Everything is connected and communicates.

BUT.
In the client program there is a button "Close connection"
That calls the closeConnection();

And when I click on the server climbs such an EOFException. Its causes are not clear to me.

How to solve this problem and what is it lies?
All code is written in order thesis.
I do not have a good knowledge of programming
Make the program and progress study.

So please do not throw stones :)

Code backend
@ServerEndpoint(value = "/server/{username}",
 encoders = MessageEncoder.class,
 decoders = MessageDecoder.class)
public class MessageServer {

 ChatRoom chatRoom = new ChatRoom();

@OnOpen
 public void onOpen(Session Session, @PathParam("username") String username) {
 chatRoom.getClients().put(username, session);
 chatRoom.sendBroadcast(new Message(username, "all", "Client" + username + " connected!"));

 System.out.println("OnOpen: Client:" + username + " connected! "+ new Date());
}

@OnMessage
 public void onMessage(Session Session, Message message) {
chatRoom.sendBroadcast(message);
}

@OnClose
 public void onClose(Session Session, @PathParam("username") String username){
 System.out.println("Client OnClose:" + username + " disconnected! "+ new Date());
}


@OnError
 public void onError(Session Session, Throwable throwable, @PathParam("username") String username) {
 System.out.println("OnError Client:" + username + "Exception:" + throwable + "" + new Date());
throwable.printStackTrace();
}

}


Part of the service code of the client part (Connection and work with sockatume)
webSocketClient = new WebSocketClient(uri) {
@Override
 public void onOpen() {
 Log.d(DebugUtils.TAG, "onOpen: OnOpen successfully!");
}

@Override
 public void onTextReceived(String json) {

 try {
 Message message = gson.fromJson(json, Message.class);
 Log.d(DebugUtils.TAG "onTextReceived:" + message.getContent());


 if (isBound) {
 Log.d(DebugUtils.TAG "onTextReceived: activity alive! sending broadcast");
 Intent intent = new Intent(App.ACTION_MESSAGE_RECEIVED);
 intent.putExtra(App.MESSAGE_EXTRA, message);
sendBroadcast(intent);

 } else {
 Log.d(DebugUtils.TAG "onTextReceived: activity dead! making notification");

 makeMessageNotification(message.getSender(), message.getContent());
}
 } catch (Exception e) {
e.printStackTrace();
 Log.d(DebugUtils.TAG "onTextReceived: Exception!!!");
}


}

@Override
 public void onBinaryReceived(byte[] data) {
 Log.d(DebugUtils.TAG "onBinaryReceived: ");
}

@Override
 public void onPingReceived(byte[] data) {
 Log.d(DebugUtils.TAG "onPingReceived: ");
}

@Override
 public void onPongReceived(byte[] data) {
 Log.d(DebugUtils.TAG "onPongReceived: ");
}

@Override
 public void onException(Exception e) {

 Log.d(DebugUtils.TAG, "onException:" + e);
}

@Override
 public void onCloseReceived() {
 Log.d(DebugUtils.TAG "onCloseReceived: ");
}
};

webSocketClient.setConnectTimeout(10000);
webSocketClient.setReadTimeout(300000);
webSocketClient.enableAutomaticReconnection(5000);
 webSocketClient.connect();


Part of the code of the service client part (close the connection)
public void closeConnection() {
webSocketClient.close();
 }


In the screenshot the server logs.

First I connect to the server
Then push the phone button closure

5e13031084630077587997.png
April 4th 20 at 00:55
1 answer
April 4th 20 at 00:57
Solution
In nikah everything is a file. Closing the connection, you close the file, what you honestly and misleading.

Wrap on the server, this accepten in the catch block
Add to your log message

The user that terminated the connection.
Thank you. Your answer saved me a lot of time : ) - megane.Stiedemann commented on April 4th 20 at 01:00

Find more questions by tags JavaAndroidJava EE