How to connect to AdonisJs socket with java socket io client?


#1

I’m trying to connect to AdonisJs socket from android (java) with socket io’s own library.
first I wanna know if its even possible? if yes then why am I unable to connect?

on android I couldn’t get the error, but when I tried to connect through chrome I got this error:

“failed: Connection closed before receiving a handshake response”

and this is my code:

``
const Ws = use(‘Ws’)

Ws.channel(‘news’, ({ socket }) => {
console.log(‘a new subscription for news topic’)
})
``
this was the code provided in the website’s guide.

My Java code:

``

private WebSocketClient mWebSocketClient;
private Socket mSocket;
{
try {
IO.Options options = new IO.Options();
options.path = “/news”;
mSocket = IO.socket(“http://192.168.10.167:3300”,options);
} catch (URISyntaxException e) {

    }
}

``


#2

First, the path in client isn’t the channel on Adonisjs WS, you may need to define the path in config/socket.js
Also, if want to write a client connecting to Adonis WS, you will need the logic flow reference to this https://github.com/adonisjs/adonis-websocket-protocol

you may have some helper method like here: https://github.com/adonisjs/adonis-websocket-packet

suggest you to have a look on the source code on official adonisjs ws client if you are creating a custom client on different platform: https://github.com/adonisjs/adonis-websocket-client