android app(cordova)是否支持socket.io client

本文探讨了在Worklight 6.1环境中使用Socket.IO插件遇到的问题及解决方法。由于Worklight对Cordova插件的支持限制,作者分享了如何在实际应用中克服这些障碍,并提供了在不同设备上测试时的具体表现。

需要使用这里的插件:
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("<div class='message'><span class='username'>" 
						+ msg.user + ":</span> " + msg.msg + "</div>");
		        $("#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上正常



转载于:https://my.oschina.net/uniquejava/blog/333013

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值