-
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) · 887 Bytes
/
Client.py
File metadata and controls
35 lines (27 loc) · 887 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
host = "127.0.0.1" # Fill the IPV4 Address of the server.
user_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
user_socket.connect((host, 65534))
print(user_socket.recv(1024).decode("utf-8"))
print(user_socket.recv(1024).decode("utf-8"))
user_socket.send(f"{input()}".encode("utf-8"))
Exit = False
def send_message():
while not Exit:
try:
message = input()
user_socket.send(message.encode("utf-8"))
except Exception as error:
print(f"Send Error:{error}")
break
def listening():
while True:
try:
print(user_socket.recv(1024).decode("utf-8"))
except Exception as e:
print(f"Error occurred: {e}")
break
t1 = threading.Thread(target=listening, daemon=True)
t1.start()
send_message()