本文介绍了套接字io android握手失败作为客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试连接到我的朋友Nodejs套接字服务器.即时通讯与此库: https://github.com/Gottox/socket.io -java-client/
Im trying to connect to my friends Nodejs socket server. im doing this with this library: https://github.com/Gottox/socket.io-java-client/
我正在尝试在后台服务中使用它.并使这部分工作.
Im trying to use this in a background service. and got this part working.
我还在新线程中添加了套接字(我不知道这是否正确)
I also have the socket in a new thread(i dont know if this is correct)
代码如下:
@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,但这没有用.我该如何使用它?
if tryied setting the default ssh but this didnt work. How can i get this to work?
推荐答案
检查以上链接以获取具有连接和消息传递功能的完整客户端/服务器代码.
Check above links for complete client/Server code with connection and messaging.
这篇关于套接字io android握手失败作为客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!