我试图连接到我的朋友Nodejs套接字服务器。我正在使用这个库:https://github.com/Gottox/socket.io-java-client/
我试图在后台服务中使用它。并使这部分工作。
我也有一个新线程中的套接字(我不知道这是否正确)
代码如下所示:
@Override
public void run() {
SocketIO socket = null;
try {
socket = new SocketIO("http://api.speebee.com:3000");
socket.connect(new IOCallback() {
@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 + "'");
}
});
} catch (MalformedURLException e) {
e.printStackTrace();
}
这会导致以下错误:
05-21 11:34:23.205 5661-5806/com.geniusgentlemen.gp_android_app
I/System.out﹕ an Error occured
05-21 11:34:23.205 5661-5806/com.geniusgentlemen.gp_android_app W/System.err﹕ io.socket.SocketIOException: Error while handshaking
05-21 11:34:23.205 5661-5806/com.geniusgentlemen.gp_android_app W/System.err﹕ at io.socket.IOConnection.handshake(IOConnection.java:322)
05-21 11:34:23.205 5661-5806/com.geniusgentlemen.gp_android_app W/System.err﹕ at io.socket.IOConnection.access$7(IOConnection.java:292)
05-21 11:34:23.205 5661-5806/com.geniusgentlemen.gp_android_app W/System.err﹕ at io.socket.IOConnection$ConnectThread.run(IOConnection.java:199)
05-21 11:34:23.205 5661-5806/com.geniusgentlemen.gp_android_app W/System.err﹕ Caused by: java.io.FileNotFoundException: http://api.speebee.com:3000/socket.io/1/
05-21 11:34:23.214 5661-5806/com.geniusgentlemen.gp_android_app W/System.err﹕ at com.android.okhttp.internal.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:206)
05-21 11:34:23.214 5661-5806/com.geniusgentlemen.gp_android_app W/System.err﹕ at io.socket.IOConnection.handshake(IOConnection.java:313)
如果尝试设置默认的ssh但这没有用。我怎样才能让它发挥作用?
答案 0 :(得分:0)