3

I downloaded the library as3-websocket-server for a desktop AIR app and it works fine on Chrome. When I use Firefox it is ok for HTTP pages, while I get an error message if I test it on HTTPS pages:

SecurityError: The operation is insecure."

I read that I should use wss:// rather than ws://, but the AIR server doesn't work with this protocol.

I tried to convert all "Socket" to "SecureSocket" in the Air App but I get an error:

1118: Implicit coercion of a value with static type flash.net:Socket to a possibly unrelated type flash.net:SecureSocket

Any idea on how to have the server available for both protocols? On the client side I could just check if I'm on HTTP or HTTPS and call the right websocket.

Thanks

Nadia
  • 247
  • 1
  • 13
  • You get the error from something like var wss:SecureSocket = new Socket(); Find this line and fix it. – Organis Mar 08 '17 at 08:10
  • no the error is from this line: var clientSocket:SecureSocket=registerClient(event.socket).socket; There is no "new Socket()" in all the code. – Nadia Mar 08 '17 at 11:16
  • Not a big difference. Please find error 1118 and read to understand: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/compilerErrors.html – Organis Mar 08 '17 at 11:35
  • I understand the meaning of the error, but I don't understand how it is generated. It says it is flash.net:Socket but i changed all the "Socket" with "SecureSocket" in the code. The library is a workaround to allow communication to websocket, so it used Socket and ServerSocket, Ijust replaced the first ones with SecureSocket". – Nadia Mar 08 '17 at 11:42
  • It means that code registerClient(event.socket).socke‌​t returns an instance of Socket class. I had a quick look at ServerSocket class and it seems that it has no option to work in SSL mode (and thus produce SecureSocket instead of regular Socket on incoming connection). – Organis Mar 08 '17 at 12:05
  • Thanks, so there is no way to manage a secure connection between AIR and a browser page? – Nadia Mar 08 '17 at 12:06
  • I think it's a matter of security policy you need to serve with the server app. Read here http://stackoverflow.com/questions/9515821/security-sandbox-violation-cant-connect-to-server-via-socket and then look here https://github.com/gimite/web-socket-js – Organis Mar 08 '17 at 12:19
  • Thanks, but i can't use an swf file in the browser, I already had it and used local connection to pass variables to the AIR app, but browsers (especially chrome) set always more difficult to use swf files and users may be not able to enable it. – Nadia Mar 08 '17 at 17:19
  • You probably need to explain what you are building in general. What app instances you have running, where they are running, what functionality you want to get in the end, etc. – Organis Mar 08 '17 at 17:30
  • Right... I have an desktop AIR app running on win and mac. It must receive some data (shipping address) from web pages (I created chrome and firefox addons for it). It worked fine with localconnection and an swf loaded in the page. But often the users have problems with SWF files and to enable them, so i rewrote the addons using an html5 websocket to send data to my air app. It works fine, but on firefox and https pages I get that issue. Users could set network.websocket.allowInsecureFromHTTPS to true in about:config, but is not a nice solution. thanks – Nadia Mar 08 '17 at 18:55
  • Have you ever considered an actual web-server? Something simple, really, PHP most probably. Running a server socket as a client app on your PC is quite a pain (and you seem to already be in pain over it). – Organis Mar 08 '17 at 19:04
  • But I shoud instasll it on each user's computer? Or can it be embedded in the air app? – Nadia Mar 08 '17 at 19:07
  • So. Let me summarize it. You want to run on the same PC a) a host application that provide some kind of make-up server functionality and b) some satellite application running in the browser and communicating with host application. I have some hard time understanding the architecture of it. If it is running on same PC, why don't you make a single application that runs in either AIR or browser? – Organis Mar 08 '17 at 19:17
  • the AIR must be a desktop app, it has some functionality that can't be run in the browser (like writing files on the HD). The data are taken from several web pages (private ecommerce, ebay, amazon) and I can't access directly to that data in other ways than opening the web page (in some case with API, but with other "permission" problems). So I think I couldn't do all inside the air app. The AIR app just "receive" the data from the web page and elaborates them. Doesn't need any more "server" function. – Nadia Mar 08 '17 at 19:31
  • (and yes, all runs on the same computer) – Nadia Mar 08 '17 at 19:40
  • Okaaay, I think I get the picture. And the problem is, when you open a page over HTTPS and Flash is not supported and you have to resort to HTML5 WebSocket, then you're getting that error. Is that correct? And, BTW, is it AIR app AS3 error or HTML5 WebSocket error? – Organis Mar 08 '17 at 19:47
  • yes, that's it. The error is given form FIREFOX (the same page on chrome works fine): "SecurityError: The operation is insecure.". If in the html5 code i change ws:// into wss:// I get no error (but the websocket server in the air app doesn't receive it). – Nadia Mar 08 '17 at 19:50
  • Now that the picture is clear it is easy to google for solution, but it seems the answer is **no, not possible**: http://stackoverflow.com/questions/9745249/html5-websocket-with-ssl Then, again, you can go for the proxy solution: your page app <-> server <-> your AIR app. – Organis Mar 08 '17 at 19:59
  • Ok, thanks! I hoped that as a workaround form air serversocket and html websocket was created, it was possible to create something similar for secure verison too. Thanks a lot for your help. – Nadia Mar 09 '17 at 08:56
  • @Nadia see if this [**article**](https://translate.google.co.uk/translate?hl=en&sl=zh-TW&u=http://blog.ben.idv.tw/2011/10/securesocket-https.html&prev=search) is useful for SecureSocket connections (not Firefox tested though). It's Google Translated from Japanese but the main study point (AS3 code) is halfway down the page. – VC.One Mar 09 '17 at 09:22
  • @Nadia Secondly... with most API's they `return` information (ie: text in JSON or XML format) based on variables within querying URL as put in browser's address box. I mean now in AS3 doesn't a simple `URLRequest` using same querying URL not return a `String` of same information? See this [**`Question`**](http://stackoverflow.com/questions/2401204/how-to-get-output-of-a-webpage-in-actionscript-3) for tips. You can also look up how to include some **header/request variables** with `URLrequest` if such is needed for some sites. – VC.One Mar 09 '17 at 09:38
  • @VC.One for the first message: thanks, I'll give a look if it could worth. For the second. I can't make the request from the AIR app, I have no credentials to get the data I need; the user must pass the data from the web page (where he is logged in) to the app. – Nadia Mar 09 '17 at 09:51

0 Answers0