# Network Libary see all servers in network

**URL:** <https://discourse.processing.org/t/network-libary-see-all-servers-in-network/16828>\
**Category:** Libraries\
**Created:** [January 3, 2020, 9:52am UTC](https://discourse.processing.org/t/network-libary-see-all-servers-in-network/16828 "2020-01-03T09:52:25Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon68884268](https://avatars.discourse-cdn.com/v4/letter/a/59ef9b/32.png) [@anon68884268](https://discourse.processing.org/u/anon68884268)\
**Post date:** [January 3, 2020, 9:52am UTC](https://discourse.processing.org/t/network-libary-see-all-servers-in-network/16828/1 "2020-01-03T09:52:25Z")

</div>

Hello,  
I am working on a whiteboard, which can be seen and edited cross devices in the same network. It works perfectly, but now i found a new Problem: Currently i’m connecting to localhost (127.0.0.1), but for cross-device i need the IP-address of the currently available servers. I want to show them in a nice drop-down list, and the user can select it. Again, they are in the same WLAN/LAN and i want NOT the IP-address of my device, i stored it in a global variable.

EDIT: The devices are sending data in JSON-Format

Thank you for listening,  
Lightosk

---

<div class="post-metadata">

**Author:** ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)\
**Post date:** [January 4, 2020, 3:29am UTC](https://discourse.processing.org/t/network-libary-see-all-servers-in-network/16828/2 "2020-01-04T03:29:58Z")

</div>

> [@anon68884268](#):
>
> but for cross-device i need the IP-address of the currently available servers

You want to discover the servers in the same network: great! Do all servers have the same functionality or each of them have a specific function? Do they have fixed ip addresses?

If they have fixed ips, you could ping those known addresses every so many seconds. However, you still need to have a “worker” to do this job. See below.

If the servers have the same functionality, you could connect to any of them. You might even consider an algorithms to connect randomly or in round-robin fashion to ensure load is distributed across all avail servers.

You could have a discovery service. How does it work? You will need to have always one server running, call it server 0 or root server. Every time a new server joins, it needs to register to this 0 server and you can always count on 0 server to provide the list of available servers. This is not enough. This 0 server needs to check the status of those registered servers say every 5 seconds. If any server fails the status check, say 3 times in a row, the server is removed from the list of available servers.

If the servers all have diff functionality then I find a small issue. How do I know what each server does? Listing a server by number is not terribly useful unless you know those ip numbers by heart and you know exactly what each server does. In other words, this would not be user friendly. In case you have a zero server, every time a server register, the server could add meta-data during the registration process like a name for the server and a description. Instead of listing IP addresses you will list the name. Alas, this sounds very close to a DNS configuration. Check on global resources how you can do this setup in a local network or check the details to see if this is a viable solution for your use case.

Just some ideas that I can think of…

Kf

---

<div class="post-metadata">

**Author:** ![anon68884268](https://avatars.discourse-cdn.com/v4/letter/a/59ef9b/32.png) [@anon68884268](https://discourse.processing.org/u/anon68884268)\
**Post date:** [January 4, 2020, 5:06pm UTC](https://discourse.processing.org/t/network-libary-see-all-servers-in-network/16828/3 "2020-01-04T17:06:27Z")

</div>

It’s a bit complicated, because i want to run the app/server at **any** network. So it’s simply not possible to configure every local network on the world, and so are no fixed IPs possible. And yes, they are all doing the same: Hosting a whiteboard, but the whiteboards are different. Now i’m displaying on server side the server’s IP, and ask on client side for that IP. Maybe it’s possible to ask the router for the current connected device, i found java code [here](https://stackoverflow.com/questions/28591427/get-all-devices-on-wifi-network-with-java) (Java code, sure translateable):

```auto
import java.net.InetAddress;
import java.net.Socket;

public class Main {
    public static void main(String[] args) {

        int timeout=500;
        int port = 1234;

        try {
            String currentIP = InetAddress.getLocalHost().toString();
            String subnet = getSubnet(currentIP);
            System.out.println("subnet: " + subnet);

            for (int i=1;i<254;i++){

                String host = subnet + i;
                System.out.println("Checking :" + host);

                if (InetAddress.getByName(host).isReachable(timeout)){
                    System.out.println(host + " is reachable");
                    try {
                        Socket connected = new Socket(subnet, port);
                    }
                    catch (Exception s) {
                        System.out.println(s);
                    }
                }
            }
        }
        catch(Exception e){
            System.out.println(e);
        }
    }

```

My program is running on port 7270, so it should be possible to ask for this port without running in other programs, see [here](https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers#Registered_ports) and [here](https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml?&page=104)

---

<div class="post-metadata">

**Author:** ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)\
**Post date:** [January 4, 2020, 5:40pm UTC](https://discourse.processing.org/t/network-libary-see-all-servers-in-network/16828/4 "2020-01-04T17:40:31Z")

</div>

> [@anon68884268](#):
>
> It’s a bit complicated, because i want to run the app/server at **any** network. So it’s simply not possible to configure every local network on the world, and so are no fixed IPs possible

Let’s say that you only have 3 servers but you will still explore all the IP range, with a timeout of 500 ms (I am guessing it is ms units here) it can take close to 128 seconds aka 2 min to explore all your available servers. These are 2 minutes that your client will not have this info. If servers has ephemeral ips, then how would you know its ip change? would you go ahead and check the whole ip space again, another 2 minutes? I am saying this is possible but not optimal.

> [@anon68884268](#):
>
> they are all doing the same: Hosting a whiteboard, but the whiteboards are different

This is confusing. Why to have multiple servers? Maybe you mean one server and multiple clients?  
You can have a single server that can manage the data and it could build the dashboard based on a client id and request parameters. Even better, the dashboard will be a different web application and this application interacts with a server to populate the dashboard.

I imagine your application to be like a chat application. A client connect to a single server which provides a chatroom. In the chatroom you can add, edit and delete messages. If a client wants to connect to a different chat room, it will send the request to this single server to render the other chat room.

Going back to your OP, what other solutions have you seen on other online communities beside the solution you shared in the last post?

Kf

---

<div class="post-metadata">

**Author:** ![anon68884268](https://avatars.discourse-cdn.com/v4/letter/a/59ef9b/32.png) [@anon68884268](https://discourse.processing.org/u/anon68884268)\
**Post date:** [January 4, 2020, 5:58pm UTC](https://discourse.processing.org/t/network-libary-see-all-servers-in-network/16828/5 "2020-01-04T17:58:27Z")

</div>

I’ve got multiple clients **and** servers. Why isn’t there just one server? The devices (one device can be a client or server) which i target (RPI Zero) have not much power, so will probably crash if they need to render multiple whiteboards.

---

<div class="post-metadata">

**Author:** ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)\
**Post date:** [January 4, 2020, 6:45pm UTC](https://discourse.processing.org/t/network-libary-see-all-servers-in-network/16828/6 "2020-01-04T18:45:09Z")

</div>

I am not familiar with RPI Zero.

A single server is a suggestion based on the limited information you shared here.

Going back to your question: You want an user to discover all the servers in your local network. Would this client send `InetAddress.getByName(host).isReachable(timeout)` to each possible IP to see if it is accessible? Would each client do that?

In the thread you shared before, they also discusses the `arp` command. You should look into it and see if it applies to your case.

Kf

---

<div class="post-metadata">

**Author:** ![Nathan](https://avatars.discourse-cdn.com/v4/letter/n/c5a1d2/32.png) [@Nathan](https://discourse.processing.org/u/Nathan)\
**Post date:** [January 6, 2020, 10:11pm UTC](https://discourse.processing.org/t/network-libary-see-all-servers-in-network/16828/7 "2020-01-06T22:11:50Z")

</div>

I believe the point they are trying to make is that you have no way of knowing which of the network devices happen to be running your application and serving up a whiteboard. As far as your server code is concerned it’s serving something and the clients should _magically_ know to talk to it. On the client side you presumably know the IP of the server for connecting manually.

To make the setup somewhat more seamless (e.g. plug and play) you must either implement some method within the client to discover what servers exist or provide a default server to connect to which will inform the client about other servers (which of course will have to talk to the primary one to register themselves).

In the latter case you can use a server with a statically configured IP address and configure all your ‘whiteboard servers’ to talk to it. That server would essentially function as a hub.

> **[Zero-configuration networking](https://en.wikipedia.org/wiki/Zero-configuration_networking)**
>
> Zero-configuration networking (zeroconf) is a set of technologies that automatically creates a usable computer network based on the Internet Protocol Suite (TCP/IP) when computers or network peripherals are interconnected. It does not require manual operator intervention or special configuration servers. Without zeroconf, a network administrator must set up network services, such as Dynamic Host Configuration Protocol (DHCP) and Domain Name System (DNS), or configure each computer's network setti...

  

> **[Multicast DNS](https://en.wikipedia.org/wiki/Multicast_DNS)**
>
> In computer networking, the multicast DNS (mDNS) protocol resolves hostnames to IP addresses within small networks that do not include a local name server. It is a zero-configuration service, using essentially the same programming interfaces, packet formats and operating semantics as the unicast Domain Name System (DNS). Although Stuart Cheshire designed mDNS as a stand-alone protocol, it can work in concert with standard DNS servers.
> The mDNS protocol is published as .mw-parser-output cite.cita...

I don’t know much about how the above works, but that might be useful in this case. If you can get that working you simply need to assign names to the servers you’re using then tell people what the name of the server they should connect to is. In this model the client can ask for a server by name and the server named that will tell the client what it’s network address is.

You can as others have pointed, have the client blindly attempt to talk to every device to see if it’s a server, or vice versa with the server seeking client. But that is horribly inefficient and may look a lot like suspicious behavior to a network administrator, particularly if it is a non-standard port…

This approach may not be ideal if security is a major concern. If so you may want to try a different approach.

---

<div class="post-metadata">

**Author:** ![anon68884268](https://avatars.discourse-cdn.com/v4/letter/a/59ef9b/32.png) [@anon68884268](https://discourse.processing.org/u/anon68884268)\
**Post date:** [July 1, 2020, 9:12am UTC](https://discourse.processing.org/t/network-libary-see-all-servers-in-network/16828/8 "2020-07-01T09:12:08Z")

</div>

To come back and solve this, I am responding now because I had a similar problem in another language and in another project and reminded this problem here: I solved it using a webserver, which holds the SSID of the network, if the network is over LAN, the public IP is used. With their SSID/IP the servers register at that server and give their local IP, too, and the clients ask the webserver for a list with the given SSID/IP and the webserver gives them all servers that registered under that SSID/IP.

Only thing I worried about, but is at least in my case very unlikely, that two SSIDs of networks match.
