-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClient.py
More file actions
35 lines (27 loc) · 726 Bytes
/
Client.py
File metadata and controls
35 lines (27 loc) · 726 Bytes
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
import socket
import threading
SERVER_IP = "127.0.0.1"
SERVER_PORT = 5213
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect((SERVER_IP, SERVER_PORT))
print(f"Connected to {SERVER_IP}:{SERVER_PORT}")
def receive():
while True:
try:
message = client.recv(1024).decode()
if message == "quit":
client.close()
break
else:
print("\b\b"+message, end="")
except:
client.close()
break
thread = threading.Thread(target=receive)
thread.start()
while True:
message = f"{input("> ")}"
if message == "/quit":
break
client.send(message.encode())
client.close()