views:

1115

answers:

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.

+1  A: 

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.

James Fassett
A: 

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.

Havenard
I'm not sure this will work with a socket connection. I'm not making URL requests. I'm using a socket and doing readInt and readBytes.
AaronLS
Well, a raw TCP connection... problem. But if you are using HTTP...
Havenard
+1  A: 

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 here) 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, can be browsed here - it's 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.

Vinay Sajip
Great, I got it working! I'll have to crank up some network monitoring tool to verify it is truly going through the proxy, but based on the source code, I am confident it is.
AaronLS
FYI, I got a 400 Bad Request through one proxy server, and then tried another and all was well. So it may have been the case that the first didn't support RFC 2817, or some other problem.
AaronLS