Android - 从 Sails 中检索套接字
Android - Retrieve Socket from Sails
我试图从我的 sails 服务器检索套接字,但从未成功。如何从帆服务器检索套接字?我到处搜索,但没有找到。
--Update--
i need some function to retrieve socket from sails which using
socket.io. My code was success to connect with sails server, but not
receieve the socket. If i implement my code for socket io only, this
will work, but for sails this code never retrieve the socket.
try {
JSONObject sendData = new JSONObject();
sendData.put("url","/user/socket");
mSocket.emit("get", sendData, new Ack() {
@Override
public void call(Object... args) {
Log.d("AC",args[0].toString());
}
});
}catch (JSONException jsonEx){
jsonEx.printStackTrace();
}
//mSocket.on("/user/hello", handleIncomingMessages);
mSocket.on("hello", handleIncomingMessages);
mSocket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
@Override
public void call(Object... args) {
Log.i("Connected","Yes");
}
});
mSocket.on(Socket.EVENT_CONNECT_ERROR, new Emitter.Listener() {
@Override
public void call(Object... args) {
Log.i("Connecting Error",args[0].toString());
}
});
mSocket.on(Socket.EVENT_RECONNECTING, new Emitter.Listener() {
@Override
public void call(Object... args) {
Log.i("Reconnecting","Yes");
}
});
mSocket.connect();
对于那些在没有任何确认的情况下投反对票的人,我不知道你想要什么以及你想要什么。我解决了我的问题,我希望它能帮助别人。在从请求缓存中检索到连接服务器的响应后,您只需移动 handleincoming 消息的代码。
try {
JSONObject sendData = new JSONObject();
sendData.put("url","/user/socket");
mSocket.emit("get", sendData, new Ack() {
@Override
public void call(Object... args) {
Log.d("AC",args[0].toString());
mSocket.on("hello", handleIncomingMessages);
}
});
}catch (JSONException jsonEx){
jsonEx.printStackTrace();
}
希望对遇到同样问题的人有所帮助
我试图从我的 sails 服务器检索套接字,但从未成功。如何从帆服务器检索套接字?我到处搜索,但没有找到。
--Update--
i need some function to retrieve socket from sails which using socket.io. My code was success to connect with sails server, but not receieve the socket. If i implement my code for socket io only, this will work, but for sails this code never retrieve the socket.
try {
JSONObject sendData = new JSONObject();
sendData.put("url","/user/socket");
mSocket.emit("get", sendData, new Ack() {
@Override
public void call(Object... args) {
Log.d("AC",args[0].toString());
}
});
}catch (JSONException jsonEx){
jsonEx.printStackTrace();
}
//mSocket.on("/user/hello", handleIncomingMessages);
mSocket.on("hello", handleIncomingMessages);
mSocket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
@Override
public void call(Object... args) {
Log.i("Connected","Yes");
}
});
mSocket.on(Socket.EVENT_CONNECT_ERROR, new Emitter.Listener() {
@Override
public void call(Object... args) {
Log.i("Connecting Error",args[0].toString());
}
});
mSocket.on(Socket.EVENT_RECONNECTING, new Emitter.Listener() {
@Override
public void call(Object... args) {
Log.i("Reconnecting","Yes");
}
});
mSocket.connect();
对于那些在没有任何确认的情况下投反对票的人,我不知道你想要什么以及你想要什么。我解决了我的问题,我希望它能帮助别人。在从请求缓存中检索到连接服务器的响应后,您只需移动 handleincoming 消息的代码。
try {
JSONObject sendData = new JSONObject();
sendData.put("url","/user/socket");
mSocket.emit("get", sendData, new Ack() {
@Override
public void call(Object... args) {
Log.d("AC",args[0].toString());
mSocket.on("hello", handleIncomingMessages);
}
});
}catch (JSONException jsonEx){
jsonEx.printStackTrace();
}
希望对遇到同样问题的人有所帮助