从android与socket.io通信 问题摘要
我正在尝试将一个简单的socket.io聊天应用程序捆绑到一个本机应用程序中,以便使用phonegap在Android 2.2及以上版本上运行 socket.io web客户端-->socket.io服务器工作 我有一个运行socket.io的简单服务器,当它在web浏览器中运行时,它成功地与socket.io客户端通信 移动浏览器中的socket.io移动客户端-->socket.io服务器正常工作 请注意,它默认返回到xhr轮询,即通过Android 2.2上的web浏览器连接时来自服务器的示例消息从android与socket.io通信 问题摘要,android,node.js,cordova,socket.io,Android,Node.js,Cordova,Socket.io,我正在尝试将一个简单的socket.io聊天应用程序捆绑到一个本机应用程序中,以便使用phonegap在Android 2.2及以上版本上运行 socket.io web客户端-->socket.io服务器工作 我有一个运行socket.io的简单服务器,当它在web浏览器中运行时,它成功地与socket.io客户端通信 移动浏览器中的socket.io移动客户端-->socket.io服务器正常工作 请注意,它默认返回到xhr轮询,即通过Android 2.2上的web浏览器连接时来自服务器的
[root@webnode-2 nodechat]#node server.js
信息-socket.io已启动
调试-客户端授权
信息-授权握手6036976111002307981
调试-设置请求GET/socket.io/1/xhr轮询/6036976111002307981?t=1332184313758
调试-设置轮询超时
调试-授权用于
调试-清除轮询超时
调试-xhr轮询写入1::
调试-为客户端6036976111002307981设置关闭超时
6036976111002307981
调试-设置请求GET/socket.io/1/xhr轮询/6036976111002307981?t=1332184339
调试-设置轮询超时
调试-清除轮询超时
调试-xhr轮询写入5::{“名称”:“消息”,“参数”:[“欢迎陌生人!”]}
调试-为客户端6036976111002307981设置关闭超时
调试-丢弃传输
调试-清除客户端6036976111002307981的关闭超时
调试-设置请求GET/socket.io/1/xhr轮询/6036976111002307981?t=1332184313928
调试-设置轮询超时
调试-丢弃传输
调试-清除客户端6036976111002307981的关闭超时
调试-清除轮询超时
调试-xhr轮询写入8::
调试-为客户端6036976111002307981设置关闭超时
调试-xhr轮询因超过持续时间而关闭
调试-设置请求GET/socket.io/1/xhr轮询/6036976111002307981?t=1332184334139
调试-设置轮询超时
调试-丢弃传输
调试-清除客户端6036976111002307981的关闭超时
调试-xhr轮询收到的数据包5::{“名称”:“连接好友”,“参数”:[{“用户id”:“2”,“好友列表”:[1,2,3,4,5,6,7,8,9,10]}
注册用户
{用户id:'2',
朋友名单:[1,2,3,4,5,6,7,8,9,10]}
10
分配的用户标识:2到插座6036976111002307981
phonegap-->socket.io服务器中的socket.io出现故障
但是,当我尝试连接phonegap中的socket.io时,连接已打开,但很快关闭
在android日志中,它有一个关于requirin flash player>v10的错误,但我的手机有flash player v11.1
03-19 11:38:46.847:I/PhoneGapLog(18469):找到日志级调试
03-19 11:38:46.847:I/PhoneGapLog(18469):将日志级别更改为调试(3)
03-19 11:38:46.847:D/DroidGap(18469):DroidGap.onCreate()
03-19 11:38:46.847:D/DroidGap(18469):DroidGap.loadUrl(file:///android_asset/www/index.html)
03-19 11:38:46.847:D/DroidGap(18469):DroidGap:url=file:///android_asset/www/index.html 基本URL=file:///android_asset/www/
03-19 11:38:46.847:D/DroidGap(18469):DroidGap.init()
03-19 11:38:46.941:D/dalvikvm(18469):GC_FOR_MALLOC在68ms内释放了6234个对象/618952字节
03-19 11:38:46.968:D/软键盘检测(18469):忽略此事件
03-19 11:38:47.007:D/软键盘检测(18469):忽略此事件
03-19 11:38:47.058:D/软键盘检测(18469):忽略此事件
03-19 11:38:47.241:D/PhoneGapLog(18469):Flash Player>=10.0.0是必需的。
03-19 11:38:47.241:D/PhoneGapLog(18469):file:///android_asset/www/js/socket.io/socket.io.js: 第2622行:Flash Player>=10.0.0是必需的。
03-19 11:38:47.241:E/Web控制台(18469):需要Flash Player>=10.0.0。在file:///android_asset/www/js/socket.io/socket.io.js:2622
03-19 11:38:47.796:D/PhoneGapLog(18469):欢迎陌生人!
03-19 11:38:47.796:D/PhoneGapLog(18469):file:///android_asset/www/index.html: 第8行:欢迎陌生人!
03-19 11:38:47.796:I/Web控制台(18469):欢迎陌生人!在file:///android_asset/www/index.html:8
03-19 11:39:07.007:E/DroidGap(18469):DroidGap:超时错误!-调用webViewClient
03-19 11:39:07.007:D/Cordova(18469):DroidGap:GapViewClient.onReceivedError:Error code=-6 Description=与服务器的连接未成功。网址=file:///android_asset/www/index.html
03-19 11:39:07.167:D/软键盘检测(18469):忽略此事件
03-19 11:39:16.323:D/dalvikvm(18469):GC_显式释放了156ms中的6130个对象/505920个字节
服务器上的事件日志为
[root@webnode-2 nodechat]#node server.js
信息-socket.io已启动
调试-客户端授权
信息-授权握手1009349893764580916
调试-设置请求GET/socket.io/1/xhr轮询/1009349893764580916?t=133218227502
调试-设置轮询超时
调试-授权用于
调试-清除轮询超时
调试-xhr轮询写入1::
调试-为客户端1009349893764580916设置关闭超时
调试-设置请求GET/socket.io/1/xhr轮询/1009349893764580916?t=1331282727602
调试-设置轮询超时
调试-清除轮询超时
调试-xhr轮询写入5::{“名称”:“消息”,“参数”:[“欢迎陌生人!”]}
调试-为客户端1009349893764580916设置关闭超时
调试-丢弃传输
调试-清除客户端1009349893764580916的关闭超时
调试-设置请求GET/socket.io/1/xhr轮询/1009349893764580916?t=1332182327802
调试-设置轮询超时
调试-丢弃传输
调试-清除客户端1009349893764580916的关闭超时
调试-清除轮询超时
信息-传输端
调试-为客户端1009349893764580916设置关闭超时
调试-清除客户端1009349893764580916的关闭超时
断开事件
调试-丢弃传输
调试-客户端授权
信息-授权握手2044675477593417130
调试-设置请求GET/socket.io/1
[root@webnode-2 nodechat]# node server.js
info - socket.io started
debug - client authorized
info - handshake authorized 6036976111002307981
debug - setting request GET /socket.io/1/xhr-polling/6036976111002307981?t=1332184313758
debug - setting poll timeout
debug - client authorized for
debug - clearing poll timeout
debug - xhr-polling writing 1::
debug - set close timeout for client 6036976111002307981
6036976111002307981
debug - setting request GET /socket.io/1/xhr-polling/6036976111002307981?t=1332184313839
debug - setting poll timeout
debug - clearing poll timeout
debug - xhr-polling writing 5:::{"name":"message","args":["Welcome stranger!"]}
debug - set close timeout for client 6036976111002307981
debug - discarding transport
debug - cleared close timeout for client 6036976111002307981
debug - setting request GET /socket.io/1/xhr-polling/6036976111002307981?t=1332184313928
debug - setting poll timeout
debug - discarding transport
debug - cleared close timeout for client 6036976111002307981
debug - clearing poll timeout
debug - xhr-polling writing 8::
debug - set close timeout for client 6036976111002307981
debug - xhr-polling closed due to exceeded duration
debug - setting request GET /socket.io/1/xhr-polling/6036976111002307981?t=1332184334139
debug - setting poll timeout
debug - discarding transport
debug - cleared close timeout for client 6036976111002307981
debug - xhr-polling received data packet 5:::{"name":"connect_friends","args":[{"user_id":"2","friends_list":[1,2,3,4,5,6,7,8,9,10]}]}
REGISTER USER
{ user_id: '2',
friends_list: [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ] }
10
assigned user_id: 2 to socket 6036976111002307981
03-19 11:38:46.847: I/PhoneGapLog(18469): Found log level DEBUG
03-19 11:38:46.847: I/PhoneGapLog(18469): Changing log level to DEBUG(3)
03-19 11:38:46.847: D/DroidGap(18469): DroidGap.onCreate()
03-19 11:38:46.847: D/DroidGap(18469): DroidGap.loadUrl(file:///android_asset/www/index.html)
03-19 11:38:46.847: D/DroidGap(18469): DroidGap: url=file:///android_asset/www/index.html baseUrl=file:///android_asset/www/
03-19 11:38:46.847: D/DroidGap(18469): DroidGap.init()
03-19 11:38:46.941: D/dalvikvm(18469): GC_FOR_MALLOC freed 6234 objects / 618952 bytes in 68ms
03-19 11:38:46.968: D/SoftKeyboardDetect(18469): Ignore this event
03-19 11:38:47.007: D/SoftKeyboardDetect(18469): Ignore this event
03-19 11:38:47.058: D/SoftKeyboardDetect(18469): Ignore this event
03-19 11:38:47.241: D/PhoneGapLog(18469): Flash Player >= 10.0.0 is required.
03-19 11:38:47.241: D/PhoneGapLog(18469): file:///android_asset/www/js/socket.io/socket.io.js: Line 2622 : Flash Player >= 10.0.0 is required.
03-19 11:38:47.241: E/Web Console(18469): Flash Player >= 10.0.0 is required. at file:///android_asset/www/js/socket.io/socket.io.js:2622
03-19 11:38:47.796: D/PhoneGapLog(18469): Receiving Welcome stranger!
03-19 11:38:47.796: D/PhoneGapLog(18469): file:///android_asset/www/index.html: Line 8 : Receiving Welcome stranger!
03-19 11:38:47.796: I/Web Console(18469): Receiving Welcome stranger! at file:///android_asset/www/index.html:8
03-19 11:39:07.007: E/DroidGap(18469): DroidGap: TIMEOUT ERROR! - calling webViewClient
03-19 11:39:07.007: D/Cordova(18469): DroidGap: GapViewClient.onReceivedError: Error code=-6 Description=The connection to the server was unsuccessful. URL=file:///android_asset/www/index.html
03-19 11:39:07.167: D/SoftKeyboardDetect(18469): Ignore this event
03-19 11:39:16.323: D/dalvikvm(18469): GC_EXPLICIT freed 6130 objects / 505920 bytes in 156ms
[root@webnode-2 nodechat]# node server.js
info - socket.io started
debug - client authorized
info - handshake authorized 1009349893764580916
debug - setting request GET /socket.io/1/xhr-polling/1009349893764580916?t=1332182327502
debug - setting poll timeout
debug - client authorized for
debug - clearing poll timeout
debug - xhr-polling writing 1::
debug - set close timeout for client 1009349893764580916
debug - setting request GET /socket.io/1/xhr-polling/1009349893764580916?t=1332182327602
debug - setting poll timeout
debug - clearing poll timeout
debug - xhr-polling writing 5:::{"name":"message","args":["Welcome stranger!"]}
debug - set close timeout for client 1009349893764580916
debug - discarding transport
debug - cleared close timeout for client 1009349893764580916
debug - setting request GET /socket.io/1/xhr-polling/1009349893764580916?t=1332182327802
debug - setting poll timeout
debug - discarding transport
debug - cleared close timeout for client 1009349893764580916
debug - clearing poll timeout
info - transport end
debug - set close timeout for client 1009349893764580916
debug - cleared close timeout for client 1009349893764580916
DISCONNECTED EVENT
debug - discarding transport
debug - client authorized
info - handshake authorized 2044675477593417130
debug - setting request GET /socket.io/1/xhr-polling/2044675477593417130?t=1332182347938
debug - setting poll timeout
debug - client authorized for
debug - clearing poll timeout
debug - xhr-polling writing 1::
debug - set close timeout for client 2044675477593417130
debug - setting request GET /socket.io/1/xhr-polling/2044675477593417130?t=1332182348112
debug - setting poll timeout
debug - clearing poll timeout
debug - xhr-polling writing 5:::{"name":"message","args":["Welcome stranger!"]}
debug - set close timeout for client 2044675477593417130
debug - discarding transport
debug - cleared close timeout for client 2044675477593417130
debug - setting request GET /socket.io/1/xhr-polling/2044675477593417130?t=1332182348308
debug - setting poll timeout
debug - discarding transport
debug - cleared close timeout for client 2044675477593417130
debug - clearing poll timeout
info - transport end
debug - set close timeout for client 2044675477593417130
debug - cleared close timeout for client 2044675477593417130
DISCONNECTED EVENT
debug - discarding transport
[root@webnode-2 nodechat]# node server.js
info - socket.io started
debug - destroying non-socket.io upgrade