我有一个 node.js/socket.io 服务器,我想创建一个 Android 应用程序来通过 websockets 进行通信。我找到了一个库:https ://github.com/koush/android-websockets 但是当我尝试使用示例代码(Socket.IO Usage)时:
SocketIOClient client = new SocketIOClient(URI.create("ws://myIP:port"), new SocketIOClient.Handler() {
String TAG = "WebSocket Handler";
@Override
public void onConnect() {
Log.d(TAG, "Connected!");
}
@Override
public void on(String event, JSONArray arguments) {
Log.d(TAG, String.format("Got event %s: %s", event, arguments.toString()));
}
@Override
public void onDisconnect(int code, String reason) {
Log.d(TAG, String.format("Disconnected! Code: %d Reason: %s", code, reason));
}
@Override
public void onError(Exception error) {
Log.e(TAG, "Error!", error);
}
});
client.connect();
(使用 IP 和端口,或 url:port)会发生以下错误:
Error!
05-19 18:03:56.065: E/WebSocket Handler(629): java.lang.IllegalStateException: Scheme 'ws' not registered.
05-19 18:03:56.065: E/WebSocket Handler(629): at org.apache.http.conn.scheme.SchemeRegistry.getScheme(SchemeRegistry.java:80)
05-19 18:03:56.065: E/WebSocket Handler(629): at org.apache.http.impl.conn.DefaultHttpRoutePlanner.determineRoute(DefaultHttpRoutePlanner.java:107)
05-19 18:03:56.065: E/WebSocket Handler(629): at org.apache.http.impl.client.DefaultRequestDirector.determineRoute(DefaultRequestDirector.java:565)
05-19 18:03:56.065: E/WebSocket Handler(629): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:292)
05-19 18:03:56.065: E/WebSocket Handler(629): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
05-19 18:03:56.065: E/WebSocket Handler(629): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
05-19 18:03:56.065: E/WebSocket Handler(629): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
05-19 18:03:56.065: E/WebSocket Handler(629): at android.net.http.AndroidHttpClient.execute(AndroidHttpClient.java:243)
05-19 18:03:56.065: E/WebSocket Handler(629): at com.codebutler.android_websockets.SocketIOClient.downloadUriAsString(SocketIOClient.java:48)
05-19 18:03:56.065: E/WebSocket Handler(629): at com.codebutler.android_websockets.SocketIOClient.access$1(SocketIOClient.java:45)
05-19 18:03:56.065: E/WebSocket Handler(629): at com.codebutler.android_websockets.SocketIOClient$3.run(SocketIOClient.java:200)
我找不到解决方案