Python Forum
Function that searches and shows all socket hosts
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Function that searches and shows all socket hosts
#1
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")
Reply
#2
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Question concerning function of a a socket pkm 4 3,863 Jun-04-2019, 07:48 AM
Last Post: DeaD_EyE
  Raw socket sendto function errors IronReign 5 6,492 Jul-09-2017, 04:46 PM
Last Post: Blue Dog
  how can I find the disk space on a remote hosts ? timfox123 1 12,116 Jun-08-2017, 08:56 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020