Adobe AIR application as a http server? - actionscript-3

Is there any way to use an Adobe AIR application as a local http server? i.e. Adobe AIR application listening to http://localhost:8020 and I'm able to use a browser to access the application? If I can, is it true or pseudo multithreading?
Is there any library or code that I can look for?

The ability to listen to ports is a new feature in AIR 2, which ought to release soon but is currently in beta. If you're using version 2 though, you could certainly create an HTTP server if you want to. A general example of building a socket server can be found here.
Note that AIR apps are event-driven, not threaded. You can of course deal with multiple connections, so I suppose the runtime itself is driving them in different threads, but the code you write doesn't deal with threading or blocking, you just register for events on connection, data, etc. and handle them. (That may be what you mean by psuedo-threaded, I'm not really up on such things.)
However, there is a very big caveat to this, which is that AIR is not currently recommended by Adobe for headless server-like applications. As I understand it, there could be cases where the runtime popped up a confirmation dialog, and some things about the app might not work correctly until you remoted into the server to dismiss the dialog.

You can use HTML Control for that.
<mx:HTML width="100%" height="100%" id="html" x="0" y="0" location="http://localhost:80/"/>

Related

call Win32 API in flex to set Window Display Affinity

I have created a Flex Desktop Application with Adobe Air.
I need to protect the application from being captured. By changing the window display affinity of the application, the application can be protected from being captured.
How to use win API in flex?
Is there any other way to protect the window from being captured?
First you have to make sure that the main window does not have the WS_EX_LAYERED Windows style. That style makes SetWindowDisplayAffinity fails with code 8 (ERROR_NOT_ENOUGH_MEMORY), at least on my machine (Seven Pro 64 bits). In your -app.xml file, set the value to false for the node <transparent> under <initialWindow>.
Second, you have to choose how to inject a regular C DLL in the application process, as the API will fail with error 5 (ERROR_ACCESS_DENIED) if you try to change the affinity of a window not living in the caller process.
One possible injection method is using the SetWindowsHookEx API. Google will give you many hits about that one. Feel free to ask for some details. You obviously needs cooperation of another process, here (and some Win32 APIs practice).
Another possible way is coding an 'ACTIONSCRIPT® Extensions for ADOBE® AIR®' (PDF).
The later seems preferable:
No collaboration from an external process needed.
Adobe AIR does the DLL loading for you.
C/C++ code much more simple.
I used the first technique, as I am more fluent in raw Win32 APIs about DLL, than I am with AIR and Action Script...
I successfully tested that first technique with a very simple "Hello World" AIR Desktop application, and get a nice "All Black" image after Print Screen.

Available Functions on FMS Server

I have a chat client that uses FMS server. I do not know how many more functions are on FSM that I can utilize. There is 0 documentation for the available FMS server. Is there a way to browse or query all the available features/functions of Adobe FMS server?
Also some of the chatters crashes my flash play remotely. I think, they are just overflowing the buffer? Is it the case? or how anyone can remotely crash my flash player? This only happens if I kick any of the specific user using the command /kick user.
FMS has pretty good doc at FMS API. But functions you want depend of who implemented server side for you.
Crash might be caused of your chat implementation. You need to find initial developer to fix that.

How to customize stream protocol to flash client

I need to create a custom communication between server and flash client. For example I want to write UDP protocol using error correction. It is much faster than TCP and does not suffer from routing problem. Unfortunately I absolutely cannot think of how to replace the existing way:
_stream = new NetStream(_connection);
_video.attachNetStream(_stream);
This encloses all communication and I do not have a control over it. I understand that I can use appendBytes, but not sure what exactly to pass to this function. I can do anything on the server side. My video is H.264 and audio is ACC.
Unless it's a AIR application, you can't. It's native API which already handling application layer (OSI model).
If you want make your own, using flash.net.DatagramSocket class (available in AIR 2+) for your application layer and NetStream.appendBytes for audio/video stream decoding & playback (feeded with FLV/F4V chunks)
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/DatagramSocket.html
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/NetStream.html#appendBytes%28%29
I was betting on UDP, but never got it working in Flash. I'll explain it:
In your browser, there is really no way to make usage of UDP!!! Flash applications there run in a sandbox, which only talk TCP!
Air is used for desktop applications, which after compilation run in a desktop wrapper, which itself has direct access to the socket and other possibilities.
That's it! You have to use TCP.

Get a stream from client microphone via web browser?

I want to implement something like voip communication that client doesn't need to install additional application, they just open the webpage and talk to a server. Is there anyway to access the audio stream from client microphone via web browser ? I don't want additional plugin like applet that user have to install.
I think flash can do this, but is there anyway else ?
Thank you,
Voteforpedro
Your four main options are:
Flash
Silverlight
ActiveX
Unsecure browser settings (e.g. javascript calling EXEs)
All of the above will be subject to various security limitations or require some acceptance by the end-user. I'm not even certain that the browser calling out to EXEs is even possible any more so it should be avoided at all costs.
Installing an ActiveX control will limit you to IE on Windows, so should probably be avoided. The user would have to agree to installing the ActiveX anyway.
Both Flash and Silverlight are cross-platform (Flash more so than Silverlight) but also require the user to agree to access to the Microphone/Webcam - this is done by the framework, not something you can control/influence. Obviously, if the user does not have Flash or Silverlight installed, you'd need to prompt the user that they need to install it!
As stated by #Oded, there are serious security and privacy issues related to microphone's and webcams, so do not expect future browsers to make this easier for you (e.g. the new family of HTML5 browsers).
There is no standard, I think flash is your best bet.
AS 3.0 Accessing a microphone.
There is no standard that gives you access to the client machine microphone.
I can imagine there are security implication to giving a browser such access, so don't expect to see anything soon, not without some sort of plug-in.
Chrome 11+ supports access to the microphone. Visit this page (with Google Chrome) and click on "Speech" and try it out. This is using Sencha Ext/Touch which is an open library. This specific addon to Sencha Touch is also open source and released here.
Edit: To clarify, this is JavaScript only. The user doesn't need to approve anything. But, it only works in Chrome and it uses Google voice recognition.
Good luck!

Anyone know about Rhomobile?

I read about http://rhomobile.com/ and I found this is great but I want to ask whether the application built with that would run in Browser or Natively on the device as this requires HTML and Ruby?
The application generated using Rhodes are pure Native application... And there is no need to install Ruby on devices as Rhodes will take core of it..
May be this URl is helpful :
http://itsallaboutruby.blogspot.com/2010/08/rhodes-framework.html
Abhishek
Both, actually.
Your application is a web application, but it doesn't run on the internet, it runs on a small webserver that is part of your application inside the phone. It also doesn't run in the browser, but rather in a native browser widget inside your application.
Since the webserver runs on the phone itself, it has access to all the native capabilities of the phone, so you can make HTTP calls to the webserver to capture sound from the microphone, shoot video with the camera, get the GPS location, get multitouch info and so on.