Detect Server without activating it

I know that I can use server.active() to detect if a server is active, but I (think I) need to initialize the server first with new Server(this, port), is there a way to check if a server is active just by using the port number?

I am guessing that if you try to create a server at a port that is already in use, you will get an error.

What is the meaning of checking the port if the port is being used by an external application or by your OS?

My thoughts are that you verify upfront you can use a port, then init the server and have a layer that keeps track of the initialized services.

Kf

I can’t do that.

I would need a server to get the initialized servers to every client but to do that I would need to check if the server was activated before to not activate it again, which is just the same problem.

Were you able to solve this problem?

I’m not clear on what the problem is that you are trying to solve. Server.active is a method that can be called on an object in memory. It sounds like you are trying to check whether another sketch running on the same system is already running a server. Is that right? If so, your sketch doesn’t have that other server in memory, so it can’t call “active” on an object it doesn’t have. It can only try to contact that server on that port and see if it responds – e.g. with a client. If it doesn’t / the port is taken, it can then decide to start its own server.

Yes @jeremydouglass I believe the intention here is to see if a host is running. Something what Minecraft has with lan servers on the network where it automatically shows you the server.

Right – I think you want to check if a host (Server) is running on another sketch using a Client:

https://processing.org/reference/libraries/net/Client.html

1 Like