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.

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();

 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());

 public void onMessage(Session Session, Message message) {

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

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


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

 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);

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

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


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

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

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

 public void onException(Exception e) {

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

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


Part of the code of the service client part (close the connection)
public void closeConnection() {

In the screenshot the server logs.

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

April 4th 20 at 00:55
1 answer
April 4th 20 at 00:57
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