-1

I designed a chat application to support a store. The chat is very important for the store because it sells and trade items, so there's lot of communication. There's two end-points, the website that contains the chat as an icon and the help desk which is accessed through a web page. I designed a chat using the socket.io library. The system is basically a web chat. I want to make an android application that will perform the help desk tasks. Using the the javascript library was a piece of cake but I am having trouble using a java package . I using Netbeans as IDE I created a project set up as java Maven. I am just testing out and afterwards I want to build an Android App as said before.

I wrote a code like this to try to connect. I add console.log on the server to check if it was connecting but nothing happens.

io.socket.client.Socket  socket =  IO.socket("https://example.com.br:3009");

JSONObject obj = new JSONObject();
obj.put("id", "null");
obj.put("nome", "android");
IO.Options ops = new IO.Options();
ops.secure = true;
ops.reconnection = true;
socket.on(io.socket.client.Socket.EVENT_CONNECT, new Emitter.Listener(){
    @Override
    public void call(Object... os) {
        socket.emit("join", obj);
        System.out.println("executou");
    }
});
socket.connect();

What am I doing wrong?

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
notExactlyAHero
  • 353
  • 1
  • 4
  • 14
  • Actually it is connecting but it is not emitting. I tried to place socket.emit after the socket.connect(); and it is not emitting. – notExactlyAHero Jul 28 '18 at 15:23

1 Answers1

0

It turned out that I had okhttp as a dependency and the version that was using 3.9.1 generates this issue. I changed it to 3.4.1 on pom.xml and it worked. I was getting exception on the Netbeans Window but I was ignoring it "okHttp3 java.lang.NoSuchMethodError: No virtual method setCallWebSocket". I thought it was a minor issue.

notExactlyAHero
  • 353
  • 1
  • 4
  • 14