-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
32 lines (25 loc) · 701 Bytes
/
client.py
File metadata and controls
32 lines (25 loc) · 701 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
import socket
import threading
HOST = 'https://pychat.up.railway.app'
PORT = 3000
def receive_message(client):
while True:
try:
message = client.recv(1024)
if not message:
break
print(message.decode())
except:
break
def start_client():
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect((HOST, PORT))
threading.Thread(target=receive_message, args=(client,)).start()
while True:
message = input()
if message.lower() == 'exit':
break
client.send(message.encode())
client.close()
if __name__ == '__main__':
start_client()