How to create flash socket policy files to open port 843 for flash application in Apache server run on windows - actionscript-3

I am creating a real time application and have come across HTML5 web-socket which is the ideal technique over ajax long polling. But web-socket is not guaranteed to run in every browser. I tested with IE-8 and IE-9, it is not supported in those versions.
I found web-socket-js which seems to be a perfect fallback for the browser not supporting modern web-socket. It uses flash for to carry out the task. But since flash 9, flash application are now required with flash socket policy file to access port 843. I have researchd in this article setting up a flash socket policy but could not find a solution that works with Apache installed in windows. How should I create this policy file and where should I put it. I am very much confused.

A policy file dictates the hosts from where .swf files can access services on the server. A policy file server is a TCP server that hosts a master policy file (an XML document) on port 843. The Flash Player first attempts to access the master policy file on this port, but if it doesn't find the policy file, requests for the file on the port on which it is trying to fetch the data.
That means the Flash Player actually makes 2 network requests. One goes to port 843 by default. If that request times out (in 3 seconds) then it makes a second request to the port you are making a connection to (presuming it's port 80 in your case).
If I remember correctly, the request is made to the following URL -
hostname:port//crossdomain.xml
In your case, I think it might just be a matter of putting the master policy file in the root of your web server. Apache uses the DocumentRoot directive in the .conf file to identify this directory.

Related

Local debugging of subdomains with VS 2015

I have a multi-tenant website that has to take care of any incoming request and determine the appropriate routing by the URL subdomain.
I set up the subdomain routing using this or a similar solution.
However I'm trying to access my website on my local machine using subdomains an alias website. I'm unable to get my local IIS to port to my website with the subdomain I've specified.
I want to dedicate a virtual domain name in my local machine that will port to the website I'm debugging on VS (localhost:23456).
I've read some answers of identical questions (like this or this one), but it looks like the system has changed with the new IIS and Visual Studio 2015 and ASP.NET 5 MVC 6 (vNext) project configuration.
Here's what I've tried according to the answers linked above:
I tried setting the hosts file porting www.myexample.com to 127.0.0.1 but I get a "Bad request" error when navigating to www.myexample.com:23456 in my browser, and anyway the debugger doesn't report a request.
I tried setting <binding protocol="http" bindingInformation=":23456:www.myexample.com" /> in the applicationhost.config file, gets IIS to raise an error saying "Replace hostname with localhost. Any other bindingInformation not specificying localhost as the website raises that IIS error.
Update
After opiants answer
I knew about the .vs folder and that's were I was configuring the bindings indeed.
However, looks like it was the permission that caused IIS to throw errors.
Running that netsh command solved the issue. And BTW, since I'm only running it my own machine, I'm not gonna need to open the firewall.
Anyway my question is if there is a way to add a wildcard instead of each subdomain separately? Since each tenant gets a unique subdomain, the whole process of adding subdomains is going to be dynamic by nature. I need to allow an asterisk in all the 3 places:
hosts file
applicationhost.config file
netsh command
It looks like I can add the asterisk in those places but it doesn't actually work.
I'm guessing you're using IIS express locally?
If so, in your solution directory, there is a .vs folder. You need to add the binding in the \config\applicationhost.config file inside that folder. Then make sure that you've allowed IIS express to listen to that subdomain.
You can refer to Scott's article on how to configure IIS Express. Specifically look for this paragraph "1. GETTING IIS EXPRESS TO SERVE EXTERNALLY OVER PORT 80"
To be more specific, you need to run these commands:
netsh http add urlacl url=http://{your-domain}:{custom-port}/ user=everyone
netsh firewall add portopening TCP {custom-port} IISExpressWeb enable ALL

Send HTTP request through browser to a program that is listening on a port

So I am trying to build a C Program that handles HTTP requests through a web browser. The program is listening on a predefined port for incoming HTTP requests and responds appropriately. It is working totally fine when I place is it in the root directory but it doesnt work when I move it to directory on its own.
For instance, this works:
localhost:9000
but this doesnt:
localhost:9000/myprogram
Any clues on how I may fix this?
Hard to answer with so few details. But to get started I would check the following:
What does the web server log say?
Is the web server configured to allow execution of [CGI] in this directory?
Are you sure you haven't mixed up the web root with the directory root, thus placing your
program in the wrong place?
Are the directory and program access modes set correctly?

unsupported address error when trying to access page on specific port in a LAN

when I try to access a page on my IIS Express in a LAN (e.g. 192.168.1.123:3766/Host/MyPage.aspx) from my HTC 8S with Windows Phone 8 I get an error message that says "Unsupported address Internet Explorer Mobile doesn't support this type of address and can't display this page.
Is it possible to get this to work and if so how?
You need to specify the protocol. Try http://192.168.1.123:3766/Host/MyPage.aspx.
You will also need to follow the instructions here to make sure that your IIS Express is serving up on a port which your phone can see.
http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj684580(v=vs.105).aspx
In particular follow this section:
Quick solution with IIS Express
Create a firewall exception to allow HTTP requests through the firewall on the port that IIS Express is using.
Get the IP address of the development computer, if necessary, by running ipconfig.
Find the IIS Express configuration file, applicationhost.config, in the folder %USERPROFILE%\Documents\IISExpress\config. The USERPROFILE environment variable typically has a value of C:\Users\.
Open applicationhost.config with Notepad or another text editor and make the following changes.
a. Find the site element for the web service, WebServiceForTesting.
b. If you don’t see the site element for the web service, you have to deploy the service at least one time to create the element.
c. Within the bindings section of the site element, copy the binding element and paste a copy directly below the existing binding element to create a second binding.
d. In the new binding element, replace localhost with the computer’s IP address.
Save the changes.
Run Visual Studio as administrator and open the Visual Studio solution.
And beware of:
Important Note:
On a corporate domain, the emulator appears as a separate network device that is not joined to the domain. As a result, you may also have to get an exception from your IT department before the emulator can connect to services that are running on the domain-joined development computer.

Connecting a socket through a Proxy in ActionScript 3

1) How would I connect through a proxy if I am using the Socket class to connect to a server?
2) If I am running my Flex application through Flash Player in a webbrowser and my webbrowser is configured to use a proxy, does the socket connection go through the proxy automatically?
Ideally, I would like to not have to depend on the web browser's settings, and be able to programmatically proxy the connection from my own code. By supporting proxies directly, I can compile it as a desktop AIR application and still support proxying the connection. Additionally, there may be cases where more than one socket connection will need to be created to different proxies.
Using Action Script 3 in Flex Builder 3.
Thanks.
You may not be able to do this with the vanilla Socket class, but check out this post by Christian Cantrell of Adobe (Google cache version) about a specialized socket class he wrote to allow "TCP socket connections through HTTP proxies in accordance with RFC 2817". His class, the winningly-named RFC2817Socket.as (github), is used by Open Flash Chart. As Christian notes in his post, there are some caveats and it may not work for you if your server doesn't support RFC 2817, or if there are certain other conditions which aren't met.
Note that on Windows, the Flash Player uses IE's proxy settings and ignores the settings of the actual browser you're using.
I've had a look and it doesn't seem possible to do exactly what you want to do. If you have control of a server you can route requests through a server yourself ... and Adobe has examples of this using their Flex Data Access services (BlazeDS and LiveCycle) to go through a proxy. Then again if you control your own server you can get it to proxy anyway you like ...
But I'm afraid there doesn't seem to be anyway to directly set a proxy on the client side using ActionScript.
As for Flash respecting the browsers proxy, I can't say I know from first-hand experience but the evidence from searching isn't good. Here is an article that claims flash won't use your browsers proxy setting for SOCKS on Linux and suggests you need to alter your iptables. There is also this adobe bug report suggesting it doesn't work for rtmp connections at least. Other anecdotal evidence suggests that it works sometimes (for HTTP requests) for some browsers.
So if you need to guarantee that a connection goes through a proxy it looks like you'll need to route your requests through a server and proxy from there.
You can't do that with a regular HTTP or SOCKS proxy. Flex shares browser's connection settings.
But you still can bypass that by using what they call PHP Proxy, basically a website which downloads another websites and forwards the result to you.

AS3 FTP Programming and the Socket and ByteArray Classes

Sorry for the subject line sounding like an even nerdier Harry Potter title.
I'm trying to use AS3's Socket class to write a simple FTP program to export as an AIR app in Flex Builder 3. I'm using an FTP server on my local network to test the program. I can successfully connect to the server (the easy part) but I can't send any commands. I'm pretty sure that you have to use the ByteArray class to send these commands but there's some crucial piece of information that I'm missing apparently. Does anyone know how to do this? Thanks!
Dave
The FTP protocol predates UTF encoding. Switch to ANSI/ASCII for better results. If you do opt for writeMultiByte instead of writeUTFBytes, be aware that it is buggy in linux. Here's one way around it.
There's another question here where the line ending turns out to be the culprit, so make sure that you get it right (as suggested above).
As said before, if this is running from the web, all socket connections will require a crossdomain policy, but this is NOT file based over HTTP. Recent changes to the security rules mean that any socket based connection must first get a crossdomain from a policy server hosted on port 843 of the target host.
Quoting from Adobe:
A SWF file may no longer make a socket connection to its own domain without a socket policy file. Prior to version 9,0,115,0, a SWF file was permitted to make socket connections to ports 1024 or greater in its own domain without a policy file.
HTTP policy files may no longer be used to authorize socket connections. Prior to version 9,0,115,0, an HTTP policy file, served from the master location of /crossdomain.xml on port 80, could be used to authorize a socket connection to any port 1024 or greater on the same host.
Essentially, what this means is that you must be in control of the target FTP host, and install supplementary software on it to get this working.
Read this link too and maybe it can be useful this one too.
The first one is about policy files and the second is an example of a TELNET (so, no FTP here) client.
I've been able to get an FTP client working in a browser, but it's buggy. I had to get a listener running on port 843 to server the policy file so that Flash would be allowed to connect and transfer data. Then, I had to figure out how FTP actually works:
You have to open 2 sockets: a command socket and a data socket. The command socket is where you send your USER, PASS, CWD, and STOR commands. The data socket is where you write your ByteArray data to. Sending the PASV command will tell you what port your data socket must connect to.
Where it is buggy is on Mac, in both Safari and FF, when I call the "socket.close()" command, the server socket actually closes. On Windoze, it does not. This is a huge problem because the Event.CLOSE event is not fired until the SERVER closes the connection. This is in the livedocs.
This is where I'm at. I have no idea why it would work flawlessly on Mac and then be completely busted in 3 different browsers on Windows. The only thing I can come up with is that it's either something in my Windows configuration that's preventing proper communication with the server, or it's the Window Flash player that's causing the problem.
Any thoughts?
We will need more info to resolve this.. What you're saying here appears correct to me. You're using the Socket class to send data though, not ByteArray.
Are you sure data is not being sent? How are you receiving the response? It may be that it's working fine but you're just not aware of it? As i said, tell us more about what you're doing..
Lee Brimelow has a screencast on gotoAndLearn of writing an POP3 client. It's essentially the same of what you're doing so take a look.
Are you 100% sure the syntax is correct? I know with HTTP you'll have to an include extra linebreak after the request for it to go through. Without it you'll get nothing back. Not sure how it is with FTP though.
The FTP standard requires CRLF at the end of commands. Try using "\r\n" in place of the "\n" in your example.
You must serve the CrossDomain Policy File from your FTP server in order to conect correctly.
From what I've gathered, you have to send each command one at a time and validate the response before moving on. You should be getting something back against ProgressEvent.SOCKET_DATA
Try just this and see what you get in response.
socket.writeUTFBytes("USER "+user+"\n"); socket.flush();
You would then read the response out like this.
var response:String = mySocket.readUTFBytes(mySocket.bytesAvailable);