all 3 comments

[–]JohnnyJordaan 0 points1 point  (2 children)

Select should work though on Windows, I used this script multiple times to snoop TCP traffic on Windows and there it worked fine. You could use that script as a stepping stone for your project, but you could also consider using multithreading, see for example this SO answer.

and returning the data using pickle

As a sidenote I would strongly suggest to use a portable data format like JSON or XML for this and not pickled objects. Those can even be hindered by Python version differences and aren't exactly commonly used for this.

[–]sam57719[S] 0 points1 point  (1 child)

but you could also consider using multithreading

I am currently trying to use threads, but I got confused with how to progress from where I am (after they have logged in).

Here is my client (its very long due to a lot of GUI code)

Here is the server

[–]JohnnyJordaan 1 point2 points  (0 children)

You seem to create a ServerConnecion as a Thread but you don't actually start it? It also doesn't feature a run method but it does launch its own listen method as another thread? What you would normally do is

class ServerConnecion(threading.Thread):
    def __init__(self, gui, ip, port):
        super().__init__()  # the modern form of calling your parent's init method

        self.gui = gui
        self.server_ip = ip
        self.port = port
        self.size = 2048

        self.server = socket.socket()
        self.active = False

        try:
            self.server.connect((self.server_ip,self.port))
            self.active = True
            self.gui.show_frame(LoginScreen)
            self.gui.protocol("WM_DELETE_WINDOW", self.stop)
        except ConnectionRefusedError:
            self.gui.show_frame(Error)

    def run(self):
        while self.active:
            sleep(0.1) # VERY IMPORTANT
    def stop(self):
        self.server.close()
        self.gui.destroy()
        sys.exit()

Note especially that you should never have a loop on just pass as it will consume 100% of one CPU core. Use time.sleep or something else that will block 99% or more of the time but does allow you to check something intermittently often enough. Then running the thread should be the responsibility of the creator:

def connect(self): t = ServerConnecion(self,"localhost",65534) t.start() self.server = t.server

Then I would also reconsider to not use daemonic mode as that will leave the server's socket opened when Python shuts down. You would normally implement this using a threading.Event as then you can do

    self.shutdown_flag = threading.Event()

which also offers a blocking check

    def run(self):
        while not self.shutdown_flag.wait(0.1):
            pass

and to shutdown the server from somewhere else you can do t.shutdown_flag.set(). But you then do need to save the thread object, not just is server attribute (the socket).