-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTCP_client.py
64 lines (43 loc) · 1.46 KB
/
TCP_client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import threading
import socket
class Client:
def __init__(self,host,port):
self.sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
self.sock.connect((host,port))
msg.tkinter.Tk()
msg.withdrwa()
self.nickname = simpledialog.askstring("Nickname", "Please choose a nickname", parent=msg)
self.gui_done = False
self.running = True
gui_thread = threading.Thread(target = self.gui_loop)
receive_thread = threading.Thread(tareget=self.receive)
gui_thread.start()
receive_thread.start()
def gui_loop(self):
slef.win = tkinter
pass
def receive(self):
pass
alias = input('Choose an alias >>> ')
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect(('10.0.2.15', 59000))
def client_receive():
while True:
try:
message = client.recv(1024).decode('utf-8')
if message == "alias?":
client.send(alias.encode('utf-8'))
else:
print(message)
except:
print('Error!')
client.close()
break
def client_send():
while True:
message = f'{alias}: {input("")}'
client.send(message.encode('utf-8'))
receive_thread = threading.Thread(target=client_receive)
receive_thread.start()
send_thread = threading.Thread(target=client_send)
send_thread.start()