commit e30d16f6d02011016428ab37af4eca9c4d5a87b7 Author: LinlyBoi Date: Sat Dec 25 01:10:55 2021 +0200 pog diff --git a/cli.py b/cli.py new file mode 100644 index 0000000..7c75a0f --- /dev/null +++ b/cli.py @@ -0,0 +1,49 @@ +import socket +import threading + +clientsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + + + +ip = input('ip: ') +#ip='www.ggsya.ga' +#ip = '41.40.24.151' +#ip = socket.getaddrinfo('ggsya.ga',9000)[0][-1] +print('trying to connect') +clientsocket.connect((ip,9000)) +print('connected') +name = input('name: ') +clientsocket.send(name.encode()) +for i in name: + try: + int(i) + print('there is a number in de name?!?!') + except: + pass + +def recievemessage(): + while True: + try: + incoming_message =clientsocket.recv(1024) # try to receive 1024 bytes + except socket.timeout: + pass + else: + print(incoming_message.decode()) + + + + +def sendmessage(): + while 1: + message = input() + clientsocket.send(message.encode()) + + +clientsocket.settimeout(0.1) + +thread = threading.Thread(target=recievemessage) +thread.start() + +sendmessage() + + diff --git a/client.py b/client.py new file mode 100644 index 0000000..c9ecd44 --- /dev/null +++ b/client.py @@ -0,0 +1,76 @@ +from tkinter import * +import socket +import threading +from time import sleep +clientsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + +window = Tk() + + +window.geometry('1200x600') + +window.title('client') + + +typingtextbox = Text(window, height=1, width=50) +typingtextbox.place(x=250, y=550, anchor=CENTER) + +chattextbox = Text(window, height=30, width=60) +chattextbox.place(x=150, y=5) + +thecurrentconnectedserver = Label() +thecurrentconnectedserver.place(x=200, y=200) + +name = input("What is your name? ") +ip = input('ip: ') +#ip = '192.168.1.6' +#ip='www.ggsya.ga' +#ip = '41.40.24.151' +#localhost = socket.gethostname() +#ip = socket.getaddrinfo('ggsya.ga',9000)[0][-1] +#print(localhost) +print('trying to connect') +clientsocket.connect((ip,9000)) +print('connected') + + + + +def recievemessage(): + print('waiting') + clientsocket.settimeout(0.1) + while True: + try: + incoming_message =clientsocket.recv(1024) # try to receive 1024 bytes + except socket.timeout: + pass + else: + incoming_message = incoming_message.decode() + chattextbox.insert(INSERT, incoming_message) + print(incoming_message) + print('waiting') + + +def sendmessage(event): + message = name +':' + typingtextbox.get('1.0', 'end-1c') + '\n' + typingtextbox.delete('1.0', END) + clientsocket.send(message.encode()) + +def sendmessagebtn(): + message = name + ':' + typingtextbox.get('1.0', 'end-1c') + '\n' + typingtextbox.delete('1.0', END) + clientsocket.send(message.encode()) + +sendbutton = Button(window, height=1, width=5, fg='red', text='send', command=sendmessagebtn) +sendbutton.place(x=260, y=537) + +clientsocket.settimeout(0.1) + +thread = threading.Thread(target=recievemessage) +thread.start() + +error_label = Label(window, height=1, width=5,text='error here',fg='red') +#error_label.place(x=1,y=1) +window.bind('',sendmessage) +window.mainloop() +