Python Forum
Function that searches and shows all socket hosts - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Networking (https://python-forum.io/forum-12.html)
+--- Thread: Function that searches and shows all socket hosts (/thread-24050.html)



Function that searches and shows all socket hosts - shaanukstar123 - Jan-28-2020

Hi,
I'm currently developing a local client-server multiplayer game using sockets, where the client has to manually connect to a server that is running by entering its IP address. Instead, I want to display all the currently running servers (Ip addresses) on their local network so that they can chose one and connect to it. Anyone know how to do this? It will be very helpful thanks.

Here's a portion of the code from the server side:
    totalConnections = 0
    port = 5555
    host=socket.gethostname() # This just gets my IP address and connects to the server with it, since I normally run the server on the same machine 
   during testing
    IP = socket.gethostbyname(host)
    server = IP
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

    try:
        s.bind((server, port))
    except socket.error as e:
        str(e)

    s.listen(2)
    print("Waiting for a connection, Server Started")



RE: Function that searches and shows all socket hosts - Gribouillis - Jan-30-2020

I don't know the general or the best solution but if I had to do something like this, I would try to use a module that already solves networking details, such as rpyc. Rpyc has a registry where servers register and this allows clients to find their server.