需要使用这里的插件:
https://github.com/Automattic/socket.io/issues/1204 https://github.com/mkuklis/phonegap-websocket https://bitbucket.org/mkuklis/phonegap-websocket-demo 不幸的是这个插件不能直接在worklight6.1中使用。 (尽管worklight6.1是基于cordova3.1做的封装<==通过在js中alert(device.cordova)中可以直接看出来),但是在worklight中不能直接使用cordova的插件,这点很不爽) http://socket.io/socket-io-with-apache-cordova/ http://www.blogjava.net/yongboy/archive/2012/05/10/377787.html 其它碰到的问题:http://answer.techwikihow.com/41184/multi-realm-authentication-forms-custom-authenticator.html
http://stackoverflow.com/questions/19934879/worklight-logoutsuccess-auth-realm-is-undefined
http://stackoverflow.com/questions/16717325/adapter-procedure-call-reporting-an-authentication-failure
http://www.giantflyingsaucer.com/blog/?p=2535 以下代码在android上打印出ReferenceError: io is not defined,mobile app到底是否支持socket.io client$(document).on("pageinit","#chatroomPage",function(res){ console.log("chatroom page init."); try{ var socket = io.connect('http://192.168.1.101:3000'); socket.on('connect', function(data) { console.log("connected to chat server."); socket.on('chat message',function(msg){ $("#incomingMessages").append(""); $("#incomingMessages").scrollTop($("#incomingMessages")[0].scrollHeight); }); }); socket.on('error', function(data) { console.log("error connect to chat server."); }); socket.on('disconnect', function(data) { console.log("you are disconnected from chat server."); }); $('#btnSend').bind('click',function(){ socket.emit('chat message', {user:loginUser,msg:$('#m').val()}); $('#m').val(''); return false; }); } catch (e){ navigator.notification.alert("socket.io error:" + e); console.log("socket.io error:", e); }});
而在simulator上正常