forked from codehouseindia/Python-Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclint.py
More file actions
33 lines (25 loc) · 733 Bytes
/
clint.py
File metadata and controls
33 lines (25 loc) · 733 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
from socket import AF_INET, socket, SOCK_STREAM
from threading import Thread
HOST = "localhost"
PORT = 5500
ADDR = (HOST, PORT)
BUFSIZ = 1024
messages = []
client_socket = socket(AF_INET, SOCK_STREAM)
client_socket.connect(ADDR)
def receive_messages():
while True:
try:
msg = client_socket.recv(BUFSIZ).decode()
messages.append(msg)
print(msg)
except Exception as e:
print("[EXCEPTION]", e)
break
def send_messages(msg):
client_socket.send(bytes(msg, "utf8"))
if msg == "{quit}":
client_socket.close()
receive_thread = Thread(target=receive_messages)
receive_thread.start()
send_messages("chirag")