Cannot connect to socket.IO in native while browser can

Cannot connect to socket.IO in native while browser can
0.0 0

#1

Hi, i cant connect to my socket.io server in simulator, android, while i can connect succesfully using browser ( Chrome)

My setup :
Cocos Creator : 1.7
Browser : Chrome
Server : socket.io 2.0.4

In simulator and android, it automatically disconnect when i call connect. ( I can connect to ws://tools.itharbors.com:4000 )

In my socket.IO server , i see that the socket.handshake of browser and native platform is different :

 ==========Browser connect===============
{ headers:
   { host: '192.168.1.37:8113',
     connection: 'keep-alive',
     accept: '*/*',
     origin: 'http://localhost:7456',
     'user-agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36
(KHTML, like Gecko) Chrome/63.0.3239.108 Safari/537.36',
     referer: 'http://localhost:7456/',
     'accept-encoding': 'gzip, deflate',
     'accept-language': 'vi-VN,vi;q=0.9,en-US;q=0.8,en;q=0.7,fr-FR;q=0.6,fr;q=0
5,ja;q=0.4,de;q=0.3',
     cookie: 'io=q8CuM0Vv8MZB-cRvAAAB' },
  time: 'Thu Jan 04 2018 20:22:33 GMT+0700 (SE Asia Standard Time)',
  address: '::ffff:192.168.1.36',
  xdomain: true,
  secure: false,
  issued: 1515072153234,
  url: '/socket.io/?token=6ad5f1be-53f2a858e7e48fee584c05&EIO=3&transport=polli
g&t=M31Leh6',
  query:
   { token: '6ad5f1be-53f2a858e7e48fee584c05',
     EIO: '3',
     transport: 'polling',
     t: 'M31Leh6' } }

==========Native connect===============
{ headers:
   { host: '192.168.1.37:8113',
     accept: '*/*',
     'accept-encoding': 'identity' },
  time: 'Thu Jan 04 2018 20:23:08 GMT+0700 (SE Asia Standard Time)',
  address: '::ffff:192.168.1.36',
  xdomain: false,
  secure: false,
  issued: 1515072188157,
  url: '/socket.io/1/?EIO=2&transport=polling&b64=true',
  query: { EIO: '2', transport: 'polling', b64: 'true' } }

#2

It seem different in the xdomain, the url path and EIO protocol, and the query is not taken along with in native platform


#3

Hmm as i read and google, cocos only connect to socket.io 0.9 while i am using 2.04, and in trello they delay the update socket.io to latest version…


#4

I am using 1.4.8 and working fine.


#5

I switch to 0.9.7, my native app works but in browser now have CORS problem :slight_smile:

Failed to load http://192.168.1.36:8113/socket.io/?token=0840c5f5-b9b9a608559ca817a77229&EIO=3&transport=polling&t=M3EGeZH: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://localhost:7456’ is therefore not allowed access.