def run(self):
        try:

            play = False
            self.conn_soc = soc.socket(soc.AF_INET, soc.SOCK_STREAM)

            self.conn_soc.connect((self.peer_host, self.peer_port))

            self.addr = self.conn_soc.getsockname()
            self.host = self.addr[0]
            self.port = self.addr[1]

            self.play = True

            print("Client Started at ", self.conn_soc.getsockname())
            print("Connection with Server:", self.conn_soc.getpeername())

        except soc.error as e:
            print(e)
            sys.exit(0)

        except KeyboardInterrupt:
            print("KeyboardInterrupt")
            sys.exit(0)
        except:
            print(trace.print_exc())
            sys.exit(0)
Beispiel #2
0
    def run(self):

        try:
            self.play = False
            self.server_soc = soc.socket(soc.AF_INET, soc.SOCK_STREAM)
            self.server_soc.setsockopt(soc.SOL_SOCKET, soc.SO_REUSEADDR, 1)

            self.server_soc.bind((self.host, self.port))

            self.server_soc.listen(1)
            print("Server now can listen at {}".format(self.server_soc.getsockname()))

            # establish a connection
            # it return connection socket and tuple with (host address, port)
            # ------------------ blocking function --------------------
            self.conn_soc, self.peer_addr = self.server_soc.accept()
            self.peer_host = self.peer_host
            self.peer_port = self.peer_port
            print("server connected to:",self.peer_addr)
            self.play = True

        except soc.error as e:
            print(e)
            sys.exit(0)

        except KeyboardInterrupt:
            print("KeyboardInterrupt")
            sys.exit(0)
        except:
            print(trace.print_exc())
            sys.exit(0)