0

I'm new to sockets, I'm trying to make connection of secured sockets. It is working fine with Http But I'm failing continuously with Https, How can I make a secured socket connection in java?

try{
    requestSocket = IO.socket(REQUEST_SOC_URL);
        } catch (URISyntaxException e) {
            e.printStackTrace();
        }
        try {
            requestSocket.on(Socket.EVENT_DISCONNECT, new Listener() {
                @Override
                public void call(Object... args) {
                }
            }).on(Socket.EVENT_CONNECT, new Listener() {
                @Override
                public void call(Object... arg0) {
                    try {
                        // emitting data here

                    } catch (JsonProcessingException e) {
                        e.printStackTrace();
                    }
                }
            }).on(Socket.EVENT_CONNECT_ERROR, new Listener() {
                @Override
                public void call(Object... arg0) {
                    System.out.println("error");
                    System.out.println(arg0[0]);
                }
            });
            requestSocket.connect();
        } catch (Exception e) {
        }
Neywat
  • 103
  • 7
D.Sunil
  • 21
  • 6
  • You say it's working fine with http, does it throws any exception when using https ? Which one ? On the line marked with _emitting data here_, how are you emitting data ? Besides, if you need to make http calls, prefer the use of a more high level api than plain sockets. – Neywat Feb 21 '20 at 12:53
  • When I'm dealing with https I'm getting xhr poll error and in front end(angular) console I'm getting : ERR_SSL_PROTOCOL_ERROR. I'm emitting data as requestSocket.emit("Test", new ObjectMapper().writeValueAsString(socketForRequest)); where socketForRequest is an Object which has data. – D.Sunil Feb 21 '20 at 13:02
  • Can you give details about ```IO``` object ? – Neywat Feb 21 '20 at 13:09
  • package io.socket.client; I'm using this [link] (https://github.com/socketio/socket.io-client-java) – D.Sunil Feb 21 '20 at 13:12
  • There are several issues opened on the project github. Did you looked at this one https://github.com/socketio/socket.io-client-java/issues/26 or this one https://github.com/socketio/socket.io-client-java/issues/88 ? – Neywat Feb 21 '20 at 13:23

0 Answers0