Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update README.md #716

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Update README.md #716

wants to merge 1 commit into from

Conversation

sup-fmarais
Copy link

Hi, I am not sure where the repo is to edit/update the documentation here: https://socketio.github.io/socket.io-client-java/initialization.html

Could you please add a section around multiplexing. I have spent hours debugging an issue on our end where we did not init the sockets correctly for multiplexing. Could save other developers a lot of time. Here are the details.

Multiplexing

When using multiplexing please ensure you create your namespaces as follow

Set the options

IO.Options options = IO.Options.builder()
    .setMultiplex(true)

Incorrect way:

Socket socket = IO.socket(URI.create("https://example.com"), options); // the main namespace
Socket productSocket = IO.socket(URI.create("https://example.com/product"), options); // the "product" namespace

socket.connect();
productSocket.connect();

The first connect() will succeed to / and /product.
The 2nd attempt will not set the socket.client.user object correctly.
See screenshots below of attempt #1 and attempt #2 using the incorrect configuration as shown above.

Correct way:

Socket socket = IO.socket(URI.create("https://example.com"), options); // the main namespace
Socket productSocket = socket.io().socket("/product"); // the "product" namespace

socket.connect();
productSocket.connect();

This will reconnect correct every time, even if you reinit and reconnect the socket multiple times.

Failure:
failure

Success:
success

Hi, I am not sure where the repo is to edit/update the documentation here: https://socketio.github.io/socket.io-client-java/initialization.html

Could you please add a section around multiplexing. I have spent hours debugging an issue on our end where we did not init the sockets correctly for multiplexing. Could save other developers a lot of time. Here are the details.

### Multiplexing
When using multiplexing please ensure you create your namespaces as follow

Set the options
```
IO.Options options = IO.Options.builder()
    .setMultiplex(true)
```

Incorrect way:
```
Socket socket = IO.socket(URI.create("https://example.com"), options); // the main namespace
Socket productSocket = IO.socket(URI.create("https://example.com/product"), options); // the "product" namespace

socket.connect();
productSocket.connect();
```
The first connect() will succeed to `/` and `/product`. 
The 2nd attempt will not set the `socket.client.user` object correctly.
See screenshots below of attempt socketio#1 and attempt socketio#2 using the incorrect configuration as shown above.

Correct way:
```
Socket socket = IO.socket(URI.create("https://example.com"), options); // the main namespace
Socket productSocket = socket.io().socket("/product"); // the "product" namespace

socket.connect();
productSocket.connect();
```
This will reconnect correct every time, even if you reinit and reconnect the socket multiple times.
@darrachequesne
Copy link
Member

Hi! That's weird, your first example should work properly:

Socket socket = IO.socket(URI.create("https://example.com"), options); // the main namespace
Socket productSocket = IO.socket(URI.create("https://example.com/product"), options); // the "product" namespace

socket.connect();
productSocket.connect();

System.out.println(socket.io() == productSocket.io()); // true

Regarding the socket.client.user object, are you using some middlewares on the server side?

@sup-fmarais
Copy link
Author

Hi there, thanks for the response! On our server side we use expressjs and socket.io.
Here is our package.json

{
    "name": "ws.superbalist.com",
    "version": "0.0.0",
    "private": true,
    "scripts": {
        "start": "node ./bin/www",
        "start-dev": "nodemon -L ./bin/www"
    },
    "dependencies": {
        "@google-cloud/pubsub": "2.19.4",
        "@superbalist/js-event-pubsub": "3.0.2",
        "@superbalist/js-pubsub-manager": "3.0.1",
        "axios": "0.21.1",
        "bluebird": "3.7.1",
        "body-parser": "1.19.0",
        "cookie-parser": "1.4.4",
        "debug": "4.1.1",
        "decimal.js": "10.2.0",
        "express": "4.17.1",
        "ip": "1.1.5",
        "jsonwebtoken": "8.5.1",
        "moment": "2.24.0",
        "morgan": "1.9.1",
        "newrelic": "6.1.0",
        "prom-client": "11.5.3",
        "pug": "2.0.4",
        "raven": "2.6.4",
        "redis": "2.8.0",
        "request": "2.88.0",
        "request-promise": "4.2.5",
        "serve-favicon": "2.5.0",
        
        # socket.io server
        "socket.io": "4.5.1",
        "socket.io-redis": "6.1.1",
        
        "uuid": "3.3.3",
        "winston": "3.3.3",
        "ws": "7.2.0"
    },
    "devDependencies": {
        "eslint": "7.32.0",
        "eslint-config-google": "0.14.0",
        "nodemon": "1.19.4",
        
        # I suspect this is for testing
        "socket.io-client": "4.1.3"
    }
}

darrachequesne added a commit that referenced this pull request Jul 8, 2022
@darrachequesne
Copy link
Member

@sup-fmarais I'm afraid this won't be sufficient for me to be able to help you...

Could you please provide a complete example?

@sup-fmarais
Copy link
Author

Sure I will try and set some time aside to do a client/server example matching our setup for you to test.

cedev935 added a commit to cedev935/socket-java that referenced this pull request Sep 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants