Communicate with other apps over TCP is Impossible?

I think a common usecase for Photoshop is to communicate with other apps. For example, If I want to send a PSD into Substance Designer or 3D Coat, or tell a game engine to import this PSD as a texture.

This form of communication is most likely going to be done via Localhost (127.0.0.1) and via the TCP protocol.

But according to this

That is intentionally not allowed. It is a security that makes sense when talking about webpages, but not about Photoshop.

To confirm this, I’ve tried connecting using WebSocket to an open TCP port on my PC (I confirmed it is open and listening by using extendscript + Socket to send the same information, and also by checking my ‘netstat -ano’ in commandprompt).

My websocket attempts always error-out, either immediately or after a delay between 5-15 seconds.

This used to be possible (still is, in fact) via Extendscript. How do I make it work in UXP? Is it impossible since I can only use Websockets and Javascript? Here are the two versions:

Functional ExtendScript
		var conn = new Socket;
		if (conn.open ("127.0.0.1:XXXXX")) 
		{
			conn.write (payload);
			conn.close();
		}
		else
		{
			alert("Export failed: Unable to connect to <LISTENER APP>.  Please make sure  <LISTENER APP> is running");
			return;
		}
Non-Functional UXP
//tried with wss, ws, and without
//onopen() never fires, 
//eventually onerror fires but the error message is blank.
    var conn = new WebSocket('wss://127.0.0.1:XXXXX')
    conn.onopen = function (e) {
      console.warn('connection established')
      console.warn('Sending Payload')
      conn.send(payload)
    }
    conn.onclose = function (event) {
      if (event.wasClean) {
        console.warn('connection closed.')
      }
    }
    conn.onerror = function (error) {
      console.error('error' + error.message)
    }

Check the Manifest file. You have to add permission to allow network communication.

Thanks for your response! I dont see anything in the example manifests or in my colleague’s old extendscript manifest which might give network access or install dependencies. If you know of an example manifest, could you point it out?

The only thing that seems to have a dependency is running your own websocket server via nodejs, such as in the websocket example here. But I don’t need to run a server, I just need to connect to an existing app that i confirmed is listening on a certain port. I haven’t gotten the websocket example to work due to the broken node JS section. Using that example to try to connect to the port I know is listening doesn’t work either. As far as I can tell, my code matches theirs in function.

I suppose my problem might be with my corporate network. That seems unlikely since the extendscript content works no problem. However, the fact remains that I have no proof the new UXP Websocket actually works in it’s current state, because the examples provided by Adobe are non-functional and irreperable for someone who is just learning javascript (AKA their target audience). I have more feedback on that in the post script.

I am still interested in help, if anyone is so inclined :slight_smile:

PS
Speaking of the official websocket example, I find it’s instructions to be lacking. I have been unable to get the example to work primarily due to the nodejs requirements. The only instruction it gives is

cd server
npm install

Which is presumptuous. The real instructions are:

  1. ensure Node JS and npm are installed. If you don’t have those, install nvm and then use that to install the first two.
  2. open a command prompt in the plugin’s root folder
  3. type
cd server
npm install

And they could definitely give some troubleshooting tips for when their own packages fail to install. For example, I had permissions issues and needed to turn of strict-ssl temporarily, since I trust Adobe to not host malicious code. And then I also had to remove the existing package-lock.json because it was resolving to a private URL or something and I was getting a 401 error unable to authenticate. After all that, I was still unable to get the install to complete properly.

Photoshop plugin development is not just for existing, seasoned javascript developers. We must be more inclusive, especially in such a splintered language. How can you not balk when looking at this official network libraries page?
https://developer.adobe.com/photoshop/uxp/guides/uxp_guide/uxp-misc/network-io/

Sure here it is: https://developer.adobe.com/photoshop/uxp/2022/guides/uxp_guide/uxp-misc/manifest-v5/#network

Thank you for the doc-link. Adding the domain name of “127.0.0.1” did not allow my connection to complete.

I did find a different example project called “desktop-helper-sample”, but that one imports the old socket io as if it were an included module, the same way that you might import photoshop.app.

This fails on my project, otherwise I could ostensibly just continue using socket.

In my case I had a bug with 127.0.0.1
So I had to use:

		"network": {
			"domains": "all"
		}

I am able to use a websocket to connect to a test website (“wss://socketsbay.com/wss/v2/1/demo/”), but still can’t do localhost. It gives me some confidence that websocket will be able to eventually do a LAN connection, but its just so strange that socket IO works fine and yet WebSocket can’t connect to it. I guess I should check with the people who are working on the other app before I continue to blame websocket.

I confirmed with my team that we use a raw TCP socket for the port I am trying to connect to. This source on the internet says that:

“The browser is a tightly locked down environment. The only socket connection that you can open from JavaScript is WebSocket.”

This source tells us that WebSocket clients cannot connect to TCP servers without the use of an external module as a middleman.

So the final answer is:
It is impossible for your UXP plugin to connect as a client to a server with a raw TCP socket using the provided modules. It might be possible if you download an external module.

I would love to be wrong about this, if anyone wants to prove it!