java sdk websocket - com.neovisionaries.ws.client.WebSocketException: The status line of the opening handshake response is empty
-
Generated the jwttoken by using api client id to get the generate session.
String clientId = "xxx"; SmartConnect smartConnect = new SmartConnect(); String apiKey = "xxx"; // Provide your API key here smartConnect.setApiKey(apiKey); User user = smartConnect.generateSession(clientId, "xxx", tOtp); System.out.println("jwt token : "+ user.getAccessToken()); String jwtToken = user.getAccessToken();
Then
SmartWebsocket smartWebsocket = new SmartWebsocket(clientId, jwtToken, apiKey, actionType, feedType); smartWebsocket.setOnConnectedListener(new SmartWSOnConnect() { @Override public void onConnected() { System.out.println("smart web socket connected.."); smartWebsocket.runscript(); } }); smartWebsocket.setOnDisconnectedListener(new SmartWSOnDisconnect() { @Override public void onDisconnected() { System.out.println("onDisconnected"); } }); /** Set error listener to listen to errors. */ smartWebsocket.setOnErrorListener(new SmartWSOnError() { @Override public void onError(Exception exception) { System.out.println("onError: " + exception.getMessage()); } @Override public void onError(SmartAPIException smartAPIException) { System.out.println("onError: " + smartAPIException.getMessage()); } @Override public void onError(String error) { System.out.println("onError: " + error); } }); smartWebsocket.setOnTickerArrivalListener(new SmartWSOnTicks() { @Override public void onTicks(JSONArray ticks) { System.out.println("ticker data: " + ticks.toString()); } }); /** * connects to SmartAPI ticker server for getting live quotes */ smartWebsocket.connect();
While connecting getting the below exception - opening handshake is empty.
com.neovisionaries.ws.client.WebSocketException: The status line of the opening handshake response is empty.
at com.neovisionaries.ws.client.HandshakeReader.readStatusLine(HandshakeReader.java:99)