def connect(self):
        server_address = self.line1.text()  # lese IP-Adresse und Port aus
        server_port = self.line2.text()

        try:
            server_port = int(str(server_port))  # konvertiere Port zu Ganzzahl
        except:
            return

        self.__my_socket = simple_socket.connect_as_client(
            server_address, server_port)

        if not self.__my_socket:  # prüfe ob Verbindung erfolgreich war
            return

        self.__nickname = self.line3.text()  # lese Username aus

        self.__my_socket.send(self.create_packet_2(
            self.__nickname, "login"))  # sende Login-Paket

        self.__socket_input_thread = threading.Thread(
            target=self.socket_input_runnable, args=())

        self.init_chat_ui()  # starte Thread und neue Darstellung

        self.__running = True

        self.__socket_input_thread.start()
Exemplo n.º 2
0
def send_thread():


    client = simple_socket.connect_as_client()
    if client:

        running = True
        while running:

            for line in sys.stdin:

                client.send(line)
Exemplo n.º 3
0
def main():
    print("------ Chat-Programm ------\n\nServer-Adresse: ", end='')
    server_address = input()
    while True:
        try:
            print("Server-Port: ", end='')
            server_port = int(input())
            if server_port >= 0 and server_port <= 65535:
                break
            else:
                print("Ungültige Eingabe!")
        except:
            print("Ungültige Eingabe!")

    print("\nNickname: ", end='')

    global nickname
    nickname = input()

    print("\nVerbinde...")

    global my_socket

    my_socket = simple_socket.connect_as_client(server_address, server_port)

    if not my_socket:
        print("\nVerbindungsaufbau fehlgeschlagen...")
        return

    my_socket.send(create_packet_2(nickname, "login"))

    global user_input_thread
    global socket_input_thread

    user_input_thread = threading.Thread(target=user_input_runnable, args=())
    socket_input_thread = threading.Thread(target=socket_input_runnable,
                                           args=())

    print("\nEingeloggt!\n")

    user_input_thread.start()
    socket_input_thread.start()
Exemplo n.º 4
0
    def launch(self):
        print("------ Chat-Programm ------\n\nServer-Adresse: ", end='')
        server_address = input()
        while True:
            try:
                print("Server-Port: ", end='')
                server_port = int(input())
                if server_port >= 0 and server_port <= 65535:
                    break
                else:
                    print("Ungültige Eingabe!")
            except:
                print("Ungültige Eingabe!")

        print("\nNickname: ", end='')

        self.__nickname = input()

        print("\nVerbinde...")

        self.__my_socket = simple_socket.connect_as_client(
            server_address, server_port)

        if not self.__my_socket:
            print("\nVerbindungsaufbau fehlgeschlagen...")
            return

        self.__my_socket.send(self.create_packet_2(self.__nickname, "login"))

        self.__user_input_thread = threading.Thread(
            target=self.user_input_runnable, args=())
        self.__socket_input_thread = threading.Thread(
            target=self.socket_input_runnable, args=())

        print("\nEingeloggt!\n")

        self.__running = True

        self.__user_input_thread.start()
        self.__socket_input_thread.start()
Exemplo n.º 5
0
# ------ jetzt eigener Code (Server) ------

# erzeugt den Socket
my_socket = simple_socket.connect_as_server()

# sende eine Nachricht
my_socket.send("Hallo Client!")

# empfange eine Nachricht
message = my_socket.receive()
print(message)

# beende die Verbindung
my_socket.close()

# ------ jetzt eigener Code (Client) ------

# erzeugt den Socket
my_socket = simple_socket.connect_as_client()

# empfange eine Nachricht
message = my_socket.receive()
print(message)

# sende eine Nachricht
my_socket.send("Hallo zurück!")

# beende die Verbindung
my_socket.close()