Friday, 27 November 2015

socket.io android.



If you google android socket.io, you will find two libs, one is the offical lib:

http://socket.io/blog/native-socket-io-and-android/

1. However, this lib doesn't support customized socket.io url. it will ignore your url and use the root url:

if you use http://localhost:9000/socket.io-xxx

it will automatically use http://localhost:9000/socket.io, because this is the default socketio url.


2. ngrok doesn't support socket.io, please don't use ngrok .

3. if you use angularjs fullstack, please change your socket.io url (as issue 1 mentioned.), you need change two place:

   1> The client service: (client/components/socket/socket.service.js)

    change path: '/socket.io-client'  to path: '/socket.io'

   2> The server  (server/app.js)

   change path: '/socket.io-client'  to path: '/socket.io

   3> change the socket.io link to:  <script src="socket.io/socket.io.js"></script> and move it out of <!-- endbuild --> don't do js minify for it.



4. socket.io doesn't supoort https very well. to be safe, you should use http.



5. serveClient: true is very important. you should always set this as true.

var socketio = require('socket.io')(server, {
  // serveClient: (config.env === 'production') ? false : true,
  serveClient: true,

Because this means the socket.io.js is not a static file, it is a runtime supported js.  "serveClient" is the flag for supporting this js runtime.

Your html links the socket.io.js to this link but it is not exist when you compile it. so the file will not be able to be minifyed.  (so you have to move this link out of js minify this is point 3. 3>)




No comments:

Post a comment