{"action":"created","issue":{"url":"https://api.github.com/repos/TooTallNate/Java-WebSocket/issues/330","labels_url":"https://api.github.com/repos/TooTallNate/Java-WebSocket/issues/330/labels{/name}","comments_url":"https://api.github.com/repos/TooTallNate/Java-WebSocket/issues/330/comments","events_url":"https://api.github.com/repos/TooTallNate/Java-WebSocket/issues/330/events","html_url":"https://github.com/TooTallNate/Java-WebSocket/issues/330","id":99601382,"number":330,"title":"Client does not transmit response","user":{"login":"AlexRomanch","id":13690854,"avatar_url":"https://avatars.githubusercontent.com/u/13690854?v=3","gravatar_id":"","url":"https://api.github.com/users/AlexRomanch","html_url":"https://github.com/AlexRomanch","followers_url":"https://api.github.com/users/AlexRomanch/followers","following_url":"https://api.github.com/users/AlexRomanch/following{/other_user}","gists_url":"https://api.github.com/users/AlexRomanch/gists{/gist_id}","starred_url":"https://api.github.com/users/AlexRomanch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AlexRomanch/subscriptions","organizations_url":"https://api.github.com/users/AlexRomanch/orgs","repos_url":"https://api.github.com/users/AlexRomanch/repos","events_url":"https://api.github.com/users/AlexRomanch/events{/privacy}","received_events_url":"https://api.github.com/users/AlexRomanch/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/TooTallNate/Java-WebSocket/labels/Client","name":"Client","color":"e102d8"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-08-07T08:03:56Z","updated_at":"2015-10-20T16:25:30Z","closed_at":null,"body":"Hi all.\r\nIn my project i use TooTallNate Websocket client in Java applet, which connected to serverEndpoint (use standard Java EE implementation javax.websocket). Each session consist of 300-400 text messages.\r\nGot one trouble - sometimes server does not receive message from client, and server forced to repeat request. Why it may happen? Client logged information, that message succesfully sent, whithout any exceptions.\r\n\n#### Client code:\r\n\r\n```java\n public void init() {\r\n        super.init();\r\n        try {\r\n         client = (WebSocketClient) AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {\r\n                public Object run() {\r\n                    try {\r\n                        return new WebSocketClient(new URI(remoteHost), new Draft_17()) {\r\n\r\n                            @Override\r\n                            public void onOpen(ServerHandshake handshakedata) {\r\n                                System.out.println(\"new connection opened\");\r\n                            }\r\n\r\n                            @Override\r\n                            public void onClose(int code, String reason, boolean remote) {\r\n                                System.out.println(\"closed with exit code \" + code + \" additional info: \" + reason);\r\n                                client.close();\r\n                            }\r\n\r\n                            @Override\r\n                            public void onMessage(String message) {\r\n                                System.out.println(\"<< Client got message: \" + message);\r\n                                String response = someLogic();\r\n                                sendMessageToServer(response);\r\n                            }\r\n\r\n                            @Override\r\n                            public void onError(Exception ex) {\r\n                                System.out.println(\"exception!\");\r\n                            }\r\n                        };\r\n                    } catch (Exception e) {\r\n                        e.printStackTrace();\r\n                        return null;\r\n                    }\r\n                }\r\n            });\r\n            AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {\r\n                public Object run() {\r\n                    try {\r\n                        client.connect();\r\n                    } catch (Exception e) {\r\n                        e.printStackTrace();\r\n                    }\r\n                    return null;\r\n                }\r\n            });\r\nprivate void sendMessageToServer(String msg) {\r\n        try{\r\n            client.send(msg);\r\n            System.out.println(\">> Send message to server: \" + msg);\r\n        }\r\n        catch(Exception ex){\r\n            ex.printStackTrace();\r\n        }\r\n    }\r\n\r```\n\r\n#### ServerEndpoint code:\r\n\r\n```java\n public class WebSocketServer {\r\n    private Session session;\r\n\r\n    public WebSocketServer() {\r\n    }\r\n\r\n    @OnOpen\r\n    public void onOpen(Session session) {\r\n        System.out.println(session.getId() + \" has opened a connection\");\r\n        this.session = session;\r\n    }\r\n    @OnMessage\r\n    public void onMessage(String message) {\r\n        System.out.println(\"<< Server got message: \" + message);\r\n        \r\n            Thread thread = new Thread(new Runnable() {\r\n                @Override\r\n                public void run() {\r\n                    String response = someLogic(message);\r\n                    session.getBasicRemote().sendText(response);\r\n                }\r\n            });\r\n            thread.start();\r\n    }\r\n    @OnClose\r\n    public void onClose(Session session) {\r\n        System.out.println(\"Session \" + session.getId() + \" has ended\");\r\n    }\r\n    @OnError\r\n    public void OnError(Throwable ex) {\r\n        ex.printStackTrace();\r\n    }\r\n```\n\r\nAny ideas? Thanks a lot."},"comment":{"url":"https://api.github.com/repos/TooTallNate/Java-WebSocket/issues/comments/149622586","html_url":"https://github.com/TooTallNate/Java-WebSocket/issues/330#issuecomment-149622586","issue_url":"https://api.github.com/repos/TooTallNate/Java-WebSocket/issues/330","id":149622586,"user":{"login":"douglasjunior","id":1512341,"avatar_url":"https://avatars.githubusercontent.com/u/1512341?v=3","gravatar_id":"","url":"https://api.github.com/users/douglasjunior","html_url":"https://github.com/douglasjunior","followers_url":"https://api.github.com/users/douglasjunior/followers","following_url":"https://api.github.com/users/douglasjunior/following{/other_user}","gists_url":"https://api.github.com/users/douglasjunior/gists{/gist_id}","starred_url":"https://api.github.com/users/douglasjunior/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/douglasjunior/subscriptions","organizations_url":"https://api.github.com/users/douglasjunior/orgs","repos_url":"https://api.github.com/users/douglasjunior/repos","events_url":"https://api.github.com/users/douglasjunior/events{/privacy}","received_events_url":"https://api.github.com/users/douglasjunior/received_events","type":"User","site_admin":false},"created_at":"2015-10-20T16:25:30Z","updated_at":"2015-10-20T16:25:30Z","body":"Try change to:\r\n```java\r\n    @OnMessage\r\n    public String onMessage(String message) {\r\n        System.out.println(\"<< Server got message: \" + message);\r\n        String response = someLogic(message);     \r\n        return response;        \r\n    }\r\n```"}}