Page 1 of 1

Does the Socket Object work through firewalls?

Posted: Tue Apr 10, 2018 10:01 am
by urbanspaceman
I've been using an Extendscript for years now that scrapes a website and brings some of its data into Photoshop. I use the Socket object to talk to the server. The problem I'm trying to solve right now is how to do this through a firewall on a corporate network...if I try this script through the firewall Photoshop simply freezes when I try the socketObj.open() command.

Anyone worked with this? It would even be an improvement to error trap it so Photoshop doesn't freeze, and I could tell the user to try another network.
I understand that the Socket Object is very limited in Extenscript, but I'm not an expert in TCP or firewalls, so I don't have too deep an understanding of it.

Thanks!

Re: Does the Socket Object work through firewalls?

Posted: Tue Apr 10, 2018 1:34 pm
by urbanspaceman
I've learned that the corporate network uses a PAC (Proxy Auto-Config) file to gain access to the web, and if I use the URL to this file as a host for the Socket Object, I get a connection. Not sure how to get to other URLs, though.

Re: Does the Socket Object work through firewalls?

Posted: Tue Apr 10, 2018 4:02 pm
by urbanspaceman
For the time being I'm throwing up an error to switch networks, which is better than Photoshop freezing. Wish I had the knowledge to reach the URL I want through the proxy, though.

Re: Does the Socket Object work through firewalls?

Posted: Wed Apr 11, 2018 4:08 pm
by urbanspaceman
OK, I think I got this working and have a better understanding.

If you’re going through a proxy you first have to set up a TCP/IP ’tunnel’ through the proxy server, using the HTTP request method ‘CONNECT’ (instead of ‘GET’). If you get the reply like

Code: Select all

HTTP/1.1 200 Connection established
from the proxy server then you can send the usual ‘GET’ request using the Socket object you’ve opened the connection with.

In my case I also had to use port 8080, so the first request to the proxy server is

Code: Select all

socket.write("CONNECT proxy.sitename.com:8080 HTTP/1.0\n\n")
[actual site name withheld] and then:

Code: Select all

socket.write("GET http://www.site.com HTTP/1.0\n\nHost:www.site.com\n\nConnection: close\n\n\n\n")
I then write the full reply to an external file and then extract the parts of the web page I need.