-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.py
34 lines (26 loc) · 681 Bytes
/
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
from dotenv import load_dotenv
import os
import socket
import threading
load_dotenv()
HOST = os.getenv("HOST_IP")
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect((HOST, 1111))
call_sign = input("CALL SIGN: ")
def receive():
while True:
try:
message = client.recv(1024)
print(message.decode())
except:
print("An error ocurred!")
client.close()
break
def send():
while True:
message = f"{call_sign}: {input('')}"
client.send(message.encode())
recv_thread = threading.Thread(target=send)
recv_thread.start()
send_thread = threading.Thread(target=receive)
send_thread.start()