我在 android 2.3 中使用 PhoneGap 和 strophe.js 连接 openfire,它成功并保持连接。
但我在 Windows Phone 7 中使用相同的代码,它首先连接并可以获取消息。但它在几分钟或几秒钟内就CONNFAIL 。
连接->认证->连接->断开->连接->断开
CONNECTED 和 DISCONNECTING 之间没有相同的时间。
var username=XXX;
var HOST_DOMAIN=XXX;
var password=XXX;
var BOSH_SERVICE = "http://127.0.0.1:7070/http-bind/";
connection = new Strophe.Connection(BOSH_SERVICE);
connection.connect(username + "@" + HOST_DOMAIN, password, onConnect);
function onConnect(status) {
if (status == Strophe.Status.CONNECTED) {
connection.addHandler(notifyUser, null, "message", null, null, null);
connection.send($pres().tree());
}else if (status == Strophe.Status.DISCONNECTED) {
console.log("Strophe is disconnected.");
}
}
function notifyUser(msg) {
console.log("msg : " + Strophe.serialize(msg));
}
没有错误信息,只有 strophe 状态日志:
Log:["status=1","DebugConsole1005374909"]
Log:["Current Status is [CONNECTING]","DebugConsole1005374910"]
Log:["Strophe is connecting.","DebugConsole1005374911"]
Log:["status=3","DebugConsole1005374912"]
Log:["Current Status is [AUTHENTICATING]","DebugConsole1005374913"]
Log:["status=5","DebugConsole1005374914"]
Log:["Strophe is connected.","DebugConsole1005374916"]
Log:["Current Status is [CONNECTED]","DebugConsole1005374915"]
GapBrowser_Navigated :: /app/www/login.html#eventList
Log:["Strophe is disconnecting.","DebugConsole1005374922"]
Log:["status=2","DebugConsole1005374917"]
Log:["Current Status is [CONNFAIL]","DebugConsole1005374918"]
Log:["Strophe failed to connect.","DebugConsole1005374919"]。
Log:["status=7","DebugConsole1005374920"]
Log:["Current Status is [DISCONNECTING]","DebugConsole1005374921"]
Log:["Strophe is disconnected.","DebugConsole1005374925"]
Log:["status=6","DebugConsole1005374923"]
Log:["Current Status is [DISCONNECTED]","DebugConsole1005374924"]
Visual Studio 2010,
Windows Phone 7.8 的 Windows Phone SDK 更新
PhoneGap-2.9.0、
Windows Phone 7、
Openfire 3.7.1、
jquery.mobile-1.2.0.min.js、
strophejs-1.0.2