-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclienttesting.py
More file actions
executable file
·43 lines (38 loc) · 905 Bytes
/
clienttesting.py
File metadata and controls
executable file
·43 lines (38 loc) · 905 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
36
37
38
39
40
41
42
43
import threading
import socket
import secret
BYTES = 256
PORT = 5050
SERVER = secret.SERVER
ADDR = (SERVER,PORT)
FORMAT = 'utf-8'
client = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
client.connect(ADDR)
def sendMessage(txt):
msg = txt.encode(FORMAT)
msg_lenght = len(msg)
send_lenght = str(msg_lenght).encode(FORMAT)
send_lenght += b' ' * (BYTES - len(send_lenght))
client.send(send_lenght)
client.send(msg)
def receiveMessage():
msg = client.recv(BYTES).decode(FORMAT)
txt = ''
for i in [x for x in msg]:
if i == '@':
print(txt)
txt = ''
txt += i
txt = ''
msg = client.recv(BYTES)
try:
while txt != '!disconnect':
txt = input('> ')
#conn, addr = client.accept()
th = [
threading.Thread(target=receiveMessage,args=()),
threading.Thread(target=sendMessage,args=(txt,)),
]
for i in th: i.start()
for i in th: i.join()
except: print('Server is disconnected.')