{"action":"reopened","issue":{"url":"https://api.github.com/repos/koush/AndroidAsync/issues/357","labels_url":"https://api.github.com/repos/koush/AndroidAsync/issues/357/labels{/name}","comments_url":"https://api.github.com/repos/koush/AndroidAsync/issues/357/comments","events_url":"https://api.github.com/repos/koush/AndroidAsync/issues/357/events","html_url":"https://github.com/koush/AndroidAsync/issues/357","id":83457018,"number":357,"title":"websocket client closed socket after connection, while chrome console keeps, why","user":{"login":"feabauer","id":7326868,"avatar_url":"https://avatars.githubusercontent.com/u/7326868?v=3","gravatar_id":"","url":"https://api.github.com/users/feabauer","html_url":"https://github.com/feabauer","followers_url":"https://api.github.com/users/feabauer/followers","following_url":"https://api.github.com/users/feabauer/following{/other_user}","gists_url":"https://api.github.com/users/feabauer/gists{/gist_id}","starred_url":"https://api.github.com/users/feabauer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/feabauer/subscriptions","organizations_url":"https://api.github.com/users/feabauer/orgs","repos_url":"https://api.github.com/users/feabauer/repos","events_url":"https://api.github.com/users/feabauer/events{/privacy}","received_events_url":"https://api.github.com/users/feabauer/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-06-01T11:55:10Z","updated_at":"2015-06-01T18:10:31Z","closed_at":null,"body":"Hi koush, thank u for your great work!\r\n\r\nI copied your sample code for websocket in webpage, one for server, and one for client.\r\n\r\nWhen I connect server with console of Chrome browser with javascript, it works well. (client sockets keep in _sockets, and NO onComplete set by  webSocket.setClosedCallback is called). When I close the websocket with \"close()\", then the onComplete will be called in server side.\r\n\r\nWhile with android client, just after websocket connects and message sent, the onComplete will be received/called soon, and the client socket will be removed from _sockets. The socket looks like closed. But when I use socket to send message, still works, so the connection is living. It makes me confused. \r\n\r\n//**********************************************\r\nCode is listed as following:\r\n\r\nserver\r\n=====================\r\nserver.websocket(\"/live\", new WebSocketRequestCallback() {\r\n            @Override\r\n            public void onConnected(final WebSocket webSocket, AsyncHttpServerRequest request) {\r\n\r\n                _sockets.add(webSocket);\r\n\r\n                //Use this to clean up any references to your websocket\r\n                webSocket.setClosedCallback(new CompletedCallback() {\r\n                    @Override\r\n                    public void onCompleted(Exception ex) {\r\n                        try {\r\n                            if (ex != null)\r\n                                Log.e(\"WebSocket\", \"Error\");\r\n                        } finally {\r\n                            _sockets.remove(webSocket);\r\n                        }\r\n                    }\r\n                });\r\n\r\n                webSocket.setStringCallback(new WebSocket.StringCallback() {\r\n                    @Override\r\n                    public void onStringAvailable(String s) {\r\n                        if (\"Hello Server\".equals(s))\r\n                            webSocket.send(\"Welcome Client!\");\r\n                    }\r\n                });\r\n\r\n                webSocket.send(\"connected.\");\r\n            }\r\n        });\r\n\r\nand android client: (within onCreate of the main activity)\r\n===================\r\n        AsyncHttpClient.getDefaultInstance().websocket(hostAddress, null, new AsyncHttpClient.WebSocketConnectCallback() {\r\n            @Override\r\n            public void onCompleted(Exception ex, WebSocket webSocket) {\r\n                if (ex != null) {\r\n                    ex.printStackTrace();\r\n                    return;\r\n                }\r\n\r\n                mSocket = webSocket;\r\n\r\n                mSocket.setStringCallback(new WebSocket.StringCallback() {\r\n                    public void onStringAvailable(String s) {\r\n                        System.out.println(\"I got a string: \" + s);\r\n                    }\r\n                });\r\n\r\n                mSocket.send(\"Hello Server\");\r\n            }\r\n        });\r\n\r\nchrome console:\r\n====================\r\nsk = new WebSocket('ws://192.168.43.1:3000/live'); \r\nsk.onopen = function(e){console.log(e);}; \r\nsk.onmessage = function(e){console.log(e);}\r\n....\r\nsk.send(\"Hello Server\")   // no call onComplete\r\n....\r\nsk.close()  //server side calls onComplete here\r\n....\r\n===============================================\r\nI check \"_sockets\" array in server side, each connection keeps well in \"_sockets\" array with chrome console, while android client, each connection will be closed/removed in server side \"webSocket.setClosedCallback\", soon after message send/received.\r\n\r\nI don't understand why the websocket will be closed by itself.\r\n\r\n Look for your help.\r\n\r\nThanks."}}