Multiple TCP connections on same computer, port, and address?

I have an app that is communicating with a specialized lighting application running on a remote computer via TCP. The lighting app is expecting a connection on a specific port, and all instances of my app (on however many computers are running it) must use the same port and connect to the same IP address that the lighting application has.

This works great, if any instance of my app queries the lighting app for data, all instances receive the data. This may sound confusing, but it’s actually great because a handy side effect is keeping all the instances in sync.

Here’s the question: If another app running on the same computer as my app wants to talk to the remote lighting app, it will need to use the same TCP configuration as my app (this is a constraint imposed by the lighting app). Is it possible for two separate apps on the same computer to bind to the same port?

The reason I’m asking is, a friend wants to write software for a third-party app to connect to the same lighting application, but my app may very well be running at the same time, on the same computer as my friend’s app…

The lighting app is handing off requests to another random port the same way a web server allows multiple connections on port 80. This also means that you can run multiple apps on your computer to that remote on the “same” port, much like connecting to a web site with multiple web browsers.

I think you’re asking if 2 CLIENT apps on the same computer can connect to a SERVER on a separate computer on the same IP address at the same time? If thats the question then the answer is yes, you can do this :slight_smile:

2 Server apps cannot listen for incoming connections on the same port on the same machine at the same time, but you’re talking about making outgoing connections, so that should work fine.

That’s not standard TCP. Are you sure this isn’t UDP?

I think Wayne answered my question (hooray!), but for those who are interested, here’s more info:

It’s not a client/server situation, the lighting app is controlling theatrical lights, my app (and others) are in some cases sending the equivalent of keyboard commands to the lighting app, other times asking the lighting app for status and configuration information, and sometimes sending configuration info to the lighting app. It’s very much a back-and-forth free-for-all.

The lighting app was originally using UDP, but switched about 4 months ago to prefer TCP. It’s still possible to use UDP, but it’s very unreliable and messy to use because the packets frequently arrive out of order - the lighting app is processing hundreds of data points and sending update commands to the lights at least 1000 times a second nonstop, so it’s pretty busy doing things more important than talking to the other apps, which have a lower priority.

And yes, if instances of my app are running on two separate computers and both of them are connected via TCP to the computer running the lighting app, a single request sent from either instance of my app to the console results in both of my apps simultaneously getting the response from the lighting app. The lighting app ignores the origin of incoming commands and essentially broadcasts to all other connected apps via TCP.

So it seems the answer is that yes, we can run two apps on my local computer and have both of them communicate with the lighting app.

Thanks everyone for the speedy answers!

Yes. If the lighting app is specifically programmed to broadcast to all connected TCP clients, then it is listening on the specified port and immediately passing each connection off to a random unused port - just like Xojo’s ServerSocket does. So your app is only making the initial connection on that port. All subsequent communication happens on a different, randomly selected, port.