NetEase / pomelo-cocos2d-js

pomelo-cocos2d-js client
101 stars 64 forks source link

在android的微信和qq浏览器访问,服务器报could not find handle invalid data package #19

Open mozackye opened 9 years ago

mozackye commented 9 years ago

我用最新的(0.1.4)pomelo-cocos2d-js 在android的微信和qq浏览器会连不上服务器,服务器报could not find handle invalid data package,其他浏览器和cocos运行正常,大概是因为pomelo-cocos2d-js的pomelo版本过低导致socket的数据包类型或格式不对,我服务器用的是pomelo1.1.9,我把模板的build.js放到客户端,这时候微信和qq浏览器访问就正常了,但我不知道怎么整合代码,也报pomelo-cocos2d-js中index.js第一句: var Util = require('util');就报错:Error: can't open : No such file or directory 纠结啊

gzw1217123 commented 7 years ago

楼主后来怎么解决的,我用的模板的build.js依旧报could not find handle invalid data package这个错

zhang-z commented 7 years ago

我的情况类似,pomelo-cocos2d-js在node v8.1.3上运行时正常,在node v6.9.5上运行时服务器会报这个错误。摸索好久发现,node 6上(new Buffer(10)).buffer.byteLength === 8192,node 8上(new Buffer(10)).buffer.byteLength === 10

解决方案是把这一行socket.send(packet) (https://github.com/NetEase/pomelo-cocos2d-js/blob/master/dist/pomelo-cocos2d-js.js#L2871) 改成:

if (packet.length === packet.buffer.byteLength) {
  socket.send(packet.buffer)
} else {
  socket.send(packet)
}

Buffer, Uint8Array, Websocket.send 这几个还没仔细研究,总之这么改在我的环境里能运行