Software Archive
Read-only legacy content

HTML5 websocket connection

Arif_B_
Beginner
892 Views

Hi,

 

Is there any special permission required to connect as a websocket client with any websocket server?

Platform Crosswalk Android

XDK latest for windows

Code:

socket = new WebSocket(webServerURL, "rtcweb");

 

Thanks

Regards

Arif

0 Kudos
14 Replies
Elroy_A_Intel
Employee
892 Views

I recommend that you include the domain name of your server in the Intent field under the Projects > <your_project> > Build Settings > Android  > Whitelist. This will allow your application to communicate with the specified web servers/domains only.

If you add an (*) asterisk to the field you will allow your application to communicate with any and all web domains. Only do this when testing your application. You can also evaluate all of the domains that your application communicates with via the Developer Console on the Debug Tab. For more information visit https://software.intel.com/en-us/xdk/docs/using-cordova-whitelist-rules-with-intel-xdk

0 Kudos
Arif_B_
Beginner
892 Views

 

Hi Elroy,

Thank you for your mail and for the guidelines, I have noticed that the code is running OK in the Emulation and in the Debug on device mode, however when I make a build and try to run it on my Android mobile, the websocket connection request to the server is not executing successfully.

As per your instructions I have set up the parameters as ( * , https://webconnect.zrg.com ;) in the  Build Settings > Android  > Whitelist > Network Request (<access>) field.

I am trying to open a secured websocket connection as follows:

 this.socket = new WebSocket("wss://webconnect.zrg.com:1080", "rtcweb");

But somehow this is not executing in the Built application, while it is running OK in Emulation and debug>device mode.

Kindly assist on where and what exactly needs to be entered for whitelist permissions.

Thanks

Regards
Arif

0 Kudos
Arif_B_
Beginner
892 Views

Hi Elroy,

Please note that as per your recommendation I have also added an asterisk ( * ) character in the Intent field under the Projects > <> > Build Settings > Android  > Whitelist.

But the result is still the same... Working OK in Emulation & on Debug device but not working with actual build.

Pls assist.

Thanks

Arif

0 Kudos
PaulF_IntelCorp
Employee
892 Views

Arif -- are you building with Crosswalk (optimize for crosswalk checked on android build settings)? When using the Debug tab you are using Crosswalk, which has the right support for webRTC.

Also, try these settings for your CSP tag in your index.html file's <head> section and the whitelist settings in the Build Settings section of the Projects tab:

<meta http-equiv="Content-Security-Policy"  content="default-src * 'unsafe-inline' 'unsafe-eval'">

Screen Shot 2016-04-19 at 7.45.46 AM.png

NOTE: these are very insecure settings, but they should help you get working, if an improper whitelist is the source of the problem.

0 Kudos
Arif_B_
Beginner
892 Views

Hi  Paul,

Yes, I am running with CrossWalk option check enabled, the build zip file size also becomes 50 MB and includes 2 files (x86 & armv7) each file is sized around 22MB, and per your advise I have added the meta tag in the index.html file also.
<meta http-equiv="Content-Security-Policy"  content="default-src * 'unsafe-inline' 'unsafe-eval'">

However there is no change in the situation...

I have further tried to change the CrossWalk version with the version 14 just to check if it is related to the build 16 but still no change.

Then finally I had opened a fresh project in XDK with a blank html5+cordova template and written the following code on a button event:

var ws = new WebSocket('wss://webconnect.zrg.com:1080');    

ws.onopen = function () 
{        
console.log('open');        
alert('Socket Connected, closing now');         
ws.close();    
};

ws.onmessage = function (event) 

{   

console.log(event.data);
alert('OnMsg');             
};
    

ws.onerror = function () 
{      
console.log('error occurred!');      
alert('OnErr');         
};

ws.onclose = function (event) 

{        
console.log('close code=' + event.code);       
alert('OnClose');             
};    

The result from the above code is also same that it is running OK in Emulation & Debug device but with actual build when connecting the websocket it generates the Error. 

The websocket OnError handler receives is a simple event not containing any detailed information:

I have tried to create a video file for your review which demonstrate my projects XDK workings, please check the following Link:

https://vimeo.com/163543622

Kindly run it in full screen, check and feedback, 

Regards

Arif

 

0 Kudos
PaulF_IntelCorp
Employee
892 Views

Arif -- I was able to reproduce the problem you describe, not clear on precisely what is going on (sorry, I'm not a websockets expert). I did find this post that might be of value > https://groups.google.com/forum/embed/#!topic/phonegap/R9RKzjwchRU. Also, this test app may be of value > http://www.websocket.org/echo.html

0 Kudos
PaulF_IntelCorp
Employee
892 Views

Arif -- I was able to make this work with the attached project. The difference between now and my previous attempt is a proxy server (firewall). In the office it did not work because I was behind a proxy. At home, I don't have that restriction, and it worked fine. The Emulate tab knows how to use the proxy server. Unfortunately, I do now know how you would setup the app to deal with a proxy server. I'm guessing this is the same problem you are having. The attached app definitely works, but as I said, only when I'm not behind our corporate proxy.

0 Kudos
Arif_B_
Beginner
892 Views

Hi Paul

Thanks, this seems to have resolved the websocket issue,

I have noticed one additional parameter is in build>settings that is intent entry has is wss:* ,

I would appreciate if you can highlight what other parameters are required which made this work.

I have tried it with a simpler project but that does not work, only the forum-625031.zip project works.

I appreciate your help on this.

Regards

Arif
 

0 Kudos
PaulF_IntelCorp
Employee
892 Views

Note also that ws protocol expects to use port 80 and the wss expects to use 443 (which are the default ports for http and https, respectively). Overriding that port is likely the reason it fails for me at work but works for me at home. I will not be able to fully test this theory until Friday.

0 Kudos
Arif_B_
Beginner
892 Views

OK, however I believe that port is not an issue because I tried the specific port 1080 & it is working OK in your app with var ws = new WebSocket('wss://webconnect.zrg.com:1080');    

But in other new app it is not working...

There must be some other permission related area... I appreciate your help...

 

Regards

Arif

0 Kudos
PaulF_IntelCorp
Employee
892 Views

Arif B. wrote:
I have noticed one additional parameter is in build>settings that is intent entry has is wss:* ,

I would appreciate if you can highlight what other parameters are required which made this work.

I made several changes at once, which is not good practice, but I was in a rush, it was late last night. So I don't know if the wss:* did the trick, or not. I'll try to do a little more testing on Friday, when I'm in the office again and behind our corporate firewall for more conclusive testing.

0 Kudos
PaulF_IntelCorp
Employee
892 Views

I undid the wss:* permissions and built the app and it all ran correctly from the office. So my proxy theory was incorrect and the permissions also seem to have been a red herring. I honestly do not know what it is about my version of the app that makes it work. Wish I could shed some light on it...

0 Kudos
Arif_B_
Beginner
892 Views

Hi,

Did you get a chance to see the issue... what needs to be configured?

Regards

Arif

0 Kudos
PaulF_IntelCorp
Employee
892 Views

Arif -- sorry, but I'm not able to reproduce the issue anymore. The sample I gave you works for me. Nothing more that I can offer at this time.

0 Kudos
Reply