socketio / socket.io-client-java

Full-featured Socket.IO Client Library for Java, which is compatible with Socket.IO v1.0 and later.
https://socketio.github.io/socket.io-client-java/installation.html
Other
5.34k stars 975 forks source link

EngineIOException: websocket error #665

Closed CupidonSauce173 closed 3 years ago

CupidonSauce173 commented 3 years ago

Hi, after few days of trying to debug this, I will post an issue here to see what's wrong.

currenctly using io.socket:socket.io-client:2.0.1 (and exluding org.json | JSON

Server side version: 4.0.0 Client side version: 2.0.1

This is the code to connect to the socket.io server

public class SocketHandler extends Application {
    URI uri = URI.create("http://142.44.136.13:443");
    IO.Options options = IO.Options.builder()
            .build();
    Socket socket = IO.socket(uri, options);

    public void onCreate() {
        super.onCreate();
        socket.on("connection", args -> Log.d("connection_event", "Connection has been established."));
        socket.on(Socket.EVENT_CONNECT_ERROR, args -> Log.d("connect_error", "error found while connecting to the socket.io server"));
        socket.connect();
    }
}

I've made a nodejs sample project to see if I can connect to the socket server and it works. Here's the simple code from another app.js

const io = require("socket.io-client");

var socket = io("http://142.44.136.13:443");
socket.on("connect_error", function(e) {
  console.log("Error while connecting: " + e)
})

I'm just wondering what I am doing wrong because I don't see an issues.

Sahara150 commented 3 years ago

Hey, did you try to add ".setTransports(new String[]{WebSocket.NAME, Polling.NAME})" to your options builder? Made me able to connect to the server, however still didn´t receive the successful connection info at client (but server connected according to log). Please let me know, if it helped you and if you have a solution to the following problem too. :D

CupidonSauce173 commented 3 years ago

No, it didn't work, still does a connection error event.

Is there a way I can get more logs from that event?

CupidonSauce173 commented 3 years ago

Here, I have this error, thanks @Sahara150 in your issue, I could print more info.

io.socket.engineio.client.EngineIOException: websocket error

CupidonSauce173 commented 3 years ago

Anyone?

CupidonSauce173 commented 3 years ago

Update : I could fix my issue which was pretty stupid and I am wondering if this is a bug. It was on my server-side. Basically, I made a user for the app and was opening the server with this command : sudo DEBUG=* nodemon server.js It seems like using a non-rooted user (even if using the sudo command) doesn't let the client with this library to connect. When running the server on the root user, everything worked, weirdly, the java library started to work. Note that the nodejs library was working fine even without the root user.