我正在使用nkzawa socket.io android客户端.如何将其连接到sails.js服务器?我尝试了从客户端(iOS和Android)发送套接字请求到Sails.js服务器和Simple Sails.js和Android示例的方法但我在我的sails服务器上遇到以下错误:
Running "watch" task
Waiting...
verbose: A socket is being allowed to connect, but the session could not be loaded. Will create an empty, one-time session to use for the life of the socket connection. Details:
Error: Session could not be loaded
at _createError (/usr/local/node-v0.12.4-linux-x64/lib/node_modules/sails/lib/hooks/session/index.js:271:21)
at Immediate._onImmediate (/usr/local/node-v0.12.4-linux-x64/lib/node_modules/sails/lib/hooks/session/index.js:274:13)
at processImmediate [as _immediateCallback] (timers.js:358:17) { [Error: Session could not be loaded] code: 'E_SESSION' }
verbose: A socket is being allowed …Run Code Online (Sandbox Code Playgroud) 我使用这个库 ( https://github.com/socketio/socket.io-client-java ) 将我的 Android 应用程序与我的 Sails socket.io 连接起来。
这是我使用的代码:
final Socket socket = IO.socket(Constants.LOCAL_URL+"?__sails_io_sdk_version=0.11.0");
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener()
{
@Override
public void call(Object... args)
{
JSONObject obj1 = new JSONObject();
try {
obj1.put("url","/rest/room");
} catch (JSONException e) {
e.printStackTrace();
}
socket.emit("get", obj1, new Ack() {
@Override
public void call(Object... args) {
Log.e("test", "GET");
}
});
Log.e("test", "CONNECT");
}
}).on("room", new Emitter.Listener()
{
@Override
public void call(Object... args)
{
Log.e("test", "ROOM");
}
});
Run Code Online (Sandbox Code Playgroud)
但是我有一个 403 原因 URL 需要身份验证。那么如何修改套接字标头以放置Cookie并保持套接字和 …
我想回拨服务器以确认我的客户端已接到电话。在相反的方向,这是大量记录并且工作正常,但是我如何从客户端确认?
注意:我在 Android 上使用 socket-io-java-client https://github.com/socketio/socket.io-client-java,而不是 JavaScript,但这应该无关紧要。好吧,也许确实如此。
socket.on("onMessage", new Emitter.Listener() {
@Override public void call(Object... args) {
// I have the args here and the last argument is a callback,
// but what do I need to do to callback the server using that arg?
}
})
Run Code Online (Sandbox Code Playgroud)
在 Swift 中它看起来像这样,但我无法弄清楚如何使用上述库在 Java 中执行此操作。
socket.on("onMessage") { data, ack in
ack?()
}
Run Code Online (Sandbox Code Playgroud)
有没有人这样做过或知道如何实现这一目标?
我在 android 中保持套接字连接时遇到问题。
我在我的应用程序中使用Socket.IO-client java 库。
当屏幕打开时,套接字连接保持不变。
但是,如果屏幕关闭,则套接字会因 ping 超时而断开连接。
我怎么解决这个问题?
我像这样打开连接。
private static final String EVENT_CONNECT = Socket.EVENT_CONNECT;
private static final String EVENT_MESSAGE = Socket.EVENT_MESSAGE;
private static final String EVENT_DISCONNECT = Socket.EVENT_DISCONNECT;
private static final String EVENT_PING = Socket.EVENT_PING;
private static final String EVENT_CONNECT_TIMEOUT = Socket.EVENT_CONNECT_TIMEOUT;
private static final String EVENT_ERROR = Socket.EVENT_ERROR;
public void connect() {
if (socket != null && socket.connected() == true) {
return;
}
IO.Options options = new IO.Options();
options.timeout = 60 * 1000; …Run Code Online (Sandbox Code Playgroud)