3 Replies Latest reply on Aug 30, 2016 10:36 AM by kerrishotts

    Websocket plugin doesn't work


      I'm working on an mobile application (with Phonegap Build) that connect to a websocket server.


      I tried many third parties plugins, adding the tag in my config.xml (widget part), but no one worked


      Examples :


      <plugin name="com.ququplay.websocket.websocket" spec="0.1.0" source="pgb" />




      <plugin spec="https://github.com/knowledgecode/WebSocket-for-Android.git" />


      I'm I writing this right or is there any thing I'm missing ?


      I have to specify that my application worked well with Android 4.4 Kitkat (which includes websocket support)




      PS : I use a hotspot to connect to my server for testing (wifi, local network, so my internet connection is off while doing this)

        • 1. Re: Websocket plugin doesn't work
          kerrishotts Adobe Community Professional

          You shouldn't need a plugin to enable web socket support. Instead use something like socket.io, which will fall back to XHR polling if web sockets aren't supported.


          On Android, I'd also suggest using Crosswalk so that you have a consistent environment across all supported targets.


          Make sure also that you:


          * Modify your content-security-policy (CSP) meta tag to allow web socket activity (ws://)

          * Make sure your config.xml whitelists your server

          • 2. Re: Websocket plugin doesn't work
            Mehdi17 Level 1

            Tanks for the answer kerrishots.


            As I said, the application wokerd on Android 4.4, so I don't think the problem concerns the CSP or the whitelist (anyway I already added an Access Origin tag before testing)


            I know about socket.io, but if I use it, I would have to rewrite both the server and client, right ? (my server is written in Java, my client in HTML / Javascript)


            My other question is how to use socket.io in this context (PhoneGap Build) : do I have to add a link in the config.xml ?

            • 3. Re: Websocket plugin doesn't work
              kerrishotts Adobe Community Professional

              1. Your server should follow RFC 6455 - The WebSocket Protocol.

              2. Socket.io is a multi-transport library that uses web sockets when it can. If it can't, it tries other methods, which would require your server to handle those other options. There are Java servers that work with Socket.io out there.

              3. You'd include it like any JavaScript script in your index.html file. See Socket.IO — Docs  for examples.

              4. There are other wrappers around the web socket API in the browser, or you can use it directly; I've had experience with Socket.io and it has fallback options, hence why I suggested it. But you don't have to use it if you don't want to. If you follow #5, you could just use the browser's web socket API directly. See https://crosswalk-project.org/documentation/apis/web_apis.html

              5. On Android, use Crosswalk. This unifies the environment across all supported Android targets, which makes for much easier testing and debugging.