Can uxp use socket to communicate with external programs?

Can uxp use socket to communicate with external programs?
Are there any solutions or examples in this area?

You can!

You actually can’t anymore!

Yes and no. You can’t (and never could, within UXP) connect to a raw TCP socket. However, you can (and I want to state this here to avoid potential confusion) communicate with web sockets (similar to the capabilities of a browser).

In the rare circumstance where you do need to connect low-level to a “raw” TCP socket, you might be able to use “Hybrid Plugins” (which are coming soon), which allow for more low-level features (but are more challenging to develop as they require additional native code) in the future.

So, all in all:

  • Can you connect to (web-) sockets? Yes.
  • Can you currently connect to raw TCP sockets? No.
  • Will this be available in UXP in the near-ish future? Probably (but with the overhead of having to deal with more low-level code).
4 Likes

This description is really helpful, thank you.

I see a number of posts in this forum where people installed socket.io and use the UXP plugin as a client, including for Photoshop plugins. For example, in XD in this post (can be seen in their dependencies) and in Photoshop here.

socket-io is definitely capable of doing raw TCP. Has the ability to use this module in UXP been explicitly removed? For example, I am trying to use it myself, and even though my npm install succeeds and all my node_modules files appear to be in their correct places relative to root, every single require() attempt fails, no matter what syntax.

I guess my question is "Can you install any npm package you want to get around the limitations in your bullet list, or do the limitations exist because UXP has an explicit ‘block list’ of modules to prevent you from doing certain things?

Really? It’s been a while since I last used it, but I was under the impression that they exclusively communicate using their protocol, which lives on top of one of two transport layers: web sockets or HTTP long polling?

Don’t get me wrong: I might be wrong here, but … based on what I remember, raw TCP support (i.e., in technical terms, support to access it on OSI level 4 instead of 5-7) would surprise me to be honest.

Are you using a build tool for your plugin? Unfortunately, UXP, different from, e.g., NodeJS, doesn’t automatically resolve packages in the node_modules folder. Thus, if you need to require() a package, you need a tool like webpack to bundle everything up.

However, not all modules are supported:

UXP doesn’t have a “block list”, but UXP is a custom JavaScript execution engine (instead of a Browser), meaning that not all functions of a Browser are implemented there. Some functionality gets added over time, while other things are excluded by design. To better understand why that is / the background behind it, I can recommend @kerrishotts ’ video.

With that, it then depends on the individual module if it makes use of something that, as of right now, isn’t supported in UXP. So, for example, using React (i.e., the react and react-dom packages) works, but some other packages might not.

1 Like

I think I’ve been confused by some old Extendscript examples. There used to be a Socket() object that you could use which does tcp easily, and I was trying to install that to this UXP plugin. All my searches online only led me to socket-io, but yeah you seem to be correct in that socket-io uses websockets under the hood.

Darn.

1 Like