我試圖用socket.io連接到由GeoloqiGottox socket.io-Java的客戶端「錯誤而握手」空指針異常
我抓起Gottox socket.io Java的託管流媒體服務器 - 客戶端代碼直接從github,並沒有做任何修改,除了更改網址,但它給了我「握手時的錯誤」消息。這個網址應該像我從Geoloqi的製作者那裏得到的那樣工作:https://community.geoloqi.com/discussion/19/data-streaming#Item_11(參見第一個回覆)。
下面是代碼,從BasicExample.java
package basic;
/*
* socket.io-java-client Test.java
*
* Copyright (c) 2012, Enno Boland
* socket.io-java-client is a implementation of the socket.io protocol in Java.
*
* See LICENSE file for more information
*/
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;
/**
* @param args
*/
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:8080/", this);
socket.connect("https://subscribe.geoloqi.com:443", this);
// Sends a string to the server.
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 + "'");
}
}
以下是錯誤消息:
an Error occured
io.socket.SocketIOException: Error while handshaking
at io.socket.IOConnection.handshake(IOConnection.java:322)
at io.socket.IOConnection.access$7(IOConnection.java:292)
at io.socket.IOConnection$ConnectThread.run(IOConnection.java:199)
Caused by: java.lang.NullPointerException
at io.socket.IOConnection.handshake(IOConnection.java:302)
... 2 more
May 1, 2013 10:02:49 PM io.socket.IOConnection cleanup
INFO: Cleanup
什麼是與代碼的問題呢?
它的工作!非常感謝。 – qwikLup 2013-05-02 04:33:47
@Adam Rosenfield嗨,先生,我有同樣的問題,我找不到任何機構來幫助我,請參閱此鏈接http://stackoverflow.com/questions/28763858/android-get-an-error-while-handshaking-謝謝 – 2015-02-27 15:36:29