WebSocket connection error WebSocketException: The status line of the opening handshake response is empty


  • We are using the below way of conneecting and generating the 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 we need to connect the websocket with the user details as below:

    public void smartWebSocketUsage(String clientId, String jwtToken, String apiKey, String actionType, String feedType)
                throws SmartAPIException {
    
            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 the websocket, we are facing this issue.. "opening handshake response is empty.."