I am working on an application that requires Websocket to communicate with my server. I work with Phonegap, so I can run all the code in the first place in my browser. Since Android 4.4 Websockets got native support on Android, so it should work ... I implemented Websocket with this code:
$(document).ready(function () { console.log('websocketready'); startwebsocket(); }); var ws; function startwebsocket() { ws = new WebSocket('ws://192.168.1.131:8080/.....'); ws.onopen = function () { console.log("Websocket Ready!!"); } ws.onclose = function () { console.log("Websocket Closed!!"); } ws.onerror = function () { console.log("Websocket Error!!"); } ws.onmessage = function (data) { console.log('getvalue : ' + data.data); } } function sendMessage(temp) { ws.send(temp); }
This works great in my browser (Chrome and firefox). But if I run the application using Phonegap on my Nexus 5 with Android 4.4.2, I get: "Connection to WebSocket with" ws: //192.168.1.131: 8080 / ..... "failed: Unexpected response code: 403
Do you have any suggestions that I might have missed, or what I did wrong?
source share