Tuesday 16 May 2017

Java socket io unknown transport undefined

When I try to connect node.js from java socket.io client I'm getting this error:

engine intercepting request for path "/socket.io/" +0ms
engine handling "GET" http request "/socket.io/1/" +0ms
engine unknown transport "undefined" +0ms

Meantime, when I try from a javascript client, works fine:

engine intercepting request for path "/socket.io/" +0ms
engine handling "GET" http request "/socket.io/?EIO=3&transport=polling&t=1494940689150-0&b64=1" +0ms
engine handshaking client "3EFWO3PTlnvZksM8AAAA" +15ms

My Java client code:

import io.socket.IOAcknowledge;
import io.socket.IOCallback;
import io.socket.SocketIO;
import io.socket.SocketIOException;

import org.json.JSONException;
import org.json.JSONObject;

public class BasicExample implements IOCallback {
    private SocketIO socket;

    public static void main(String[] args) {
        try {
            new BasicExample();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public BasicExample() throws Exception {

            socket = new SocketIO();
            socket.connect("http://localhost:9990", this);

            socket.send("Hello Server");

            // Sends a JSON object to the server.
            socket.send(new JSONObject().put("key", "value").put("key2","another value"));

            // Emits an event to the server.
            socket.emit("event", "argument1", "argument2", 13.37);
    }

    @Override
    public void onMessage(JSONObject json, IOAcknowledge ack) {
        try {
            System.out.println("Server said:" + json.toString(2));
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onMessage(String data, IOAcknowledge ack) {
        System.out.println("Server said: " + data);
    }

    @Override
    public void onError(SocketIOException socketIOException) {
        System.out.println("an Error occured");
        socketIOException.printStackTrace();
    }

    @Override
    public void onDisconnect() {
        System.out.println("Connection terminated.");
    }

    @Override
    public void onConnect() {
        System.out.println("Connection established");
    }

    @Override
    public void on(String event, IOAcknowledge ack, Object... args) {
        System.out.println("Server triggered event '" + event + "'");
    }
}

In Java, I'm using socketio.jar downloaded from here http://www.java2s.com/Code/Jar/s/Downloadsocketiojar.htm, wich seems was compiled from here https://github.com/Gottox/socket.io-java-client

In node.js server I'm user socket.io@1.0.6 version.

Please, can someone help me?



via user3078383

No comments:

Post a Comment