@m_adam said in How to get mouse drag info from external through Python API?:
Hi sorry about the confusion of server.close I was referring to self.sock.close.
After some tests the main issue with your code is currently recvfrom is blocking, meaning until it receives something all the code is blocked, so TestBreak is never called and the thread never ends.
So using timeout solve the issue.
import c4d
import socket
class A(c4d.threading.C4DThread):
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    end = False
    
    def Main(self):
            
        self.sock.bind(("localhost", 20014))
        while True:
            # use timeout to check for TestBreak()
            try:
                self.sock.settimeout(1.0)
                self.sock.listen(1)
                conn, addr = self.sock.accept()
                # connection  
                print('Connection address:' + str(addr))
            
                data = conn.recv(BUFFER_SIZE)
                if not data:
                    print("Got no data.")
                    break
                else:
                    print("received data:" + str(data))
                    print str(data)
                    self._data = str(data)
                    # DO SOMETHING
            
                conn.close()
            # timeout
            except:
                if self.TestBreak():
                    self.sock.close()
                    self.End()
                    return
                continue
        self.sock.close()
if __name__ == "__main__":
    threadedServer = A()
    threadedServer.Start()
Cheers,
Maxime.
Awosome, the whole script works very well now, thanks man, you help me quite a lot! mua~