gpt4 book ai didi

javascript - Java套接字io未知传输未定义

转载 作者:行者123 更新时间:2023-12-02 13:09:51 24 4
gpt4 key购买 nike

当我尝试从 java socket.io 客户端连接 node.js 时,出现此错误:

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

同时,当我从 JavaScript 客户端尝试时,工作正常:

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

我的Java客户端代码:

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 + "'");
}
}

在Java中,我使用从这里下载的socketio.jar http://www.java2s.com/Code/Jar/s/Downloadsocketiojar.htm ,这似乎是从这里编译的 https://github.com/Gottox/socket.io-java-client

在node.js服务器中,我是用户socket.io@1.0.6版本。

请问有人可以帮助我吗?

最佳答案

这个客户端看起来已经过时了大约 5 年。看来这是一个较新的:https://github.com/socketio/socket.io-client-java

关于javascript - Java套接字io未知传输未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44005843/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com