-
Notifications
You must be signed in to change notification settings - Fork 52
/
chat_clnt.py
44 lines (34 loc) · 829 Bytes
/
chat_clnt.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
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python3
from socket import *
from threading import Thread
def receive():
while True:
msg = client_socket.recv(BUFSIZ).decode("utf8")
if msg == "{quit}":
client_socket.close()
break
if not msg:
break
print(msg)
def send():
while True:
msg = input()
client_socket.send(bytes(msg, "utf8"))
if msg == "{quit}":
break
HOST = input('Enter host: ')
PORT = input('Enter port: ')
if not PORT:
PORT = 33000
else:
PORT = int(PORT)
BUFSIZ = 1024
ADDR = (HOST, PORT)
client_socket = socket(AF_INET, SOCK_STREAM)
client_socket.connect(ADDR)
receive_thread = Thread(target=receive)
send_thread = Thread(target=send)
receive_thread.start()
send_thread.start()
receive_thread.join()
send_thread.join()