Socket.IO 连接 Params Android

Aqi*_*ash 1 android ios socket.io

我们正在 iOS 和 Android 上开发一个应用程序,其中包括用于快速消息传递的 socket.io 的实现。

对于 iOS,我们使用带参数的套接字连接,我们在配置中发送“user_id”,服务器接收它。

我们无法找到,相同方案的 Android 实现。

以下是iOS代码。

// creating dictionary/json to be sent on connection
var dic = NSMutableDictionary()
dic.setValue(["user_id": Profile().getProfile(atr: "_id") as! String], forKey: "connectParams")

// creating socket.io object and passing dictionary into config
socket = SocketIOClient(socketURL: NSURL(string: "http://something.com")!, config: dic as! NSDictionary )
socket!.connect() // works perfectly
Run Code Online (Sandbox Code Playgroud)

小智 7

我认为你必须这样做。请尝试一下,让我知道它是否适合您。

Socket socket = null;

try {
    IO.Options mOptions = new IO.Options();
    mOptions.query = "userId=" + mUserId;
    socket = IO.socket(url, mOptions);
} catch (URISyntaxException e) {
    return Observable.error(e);
}
socket.connect();
Run Code Online (Sandbox Code Playgroud)