-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
46 lines (32 loc) · 869 Bytes
/
run.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
import fun
import time
import socket
import threading
HOST = 'localhost'
ct = socket.socket()
def write():
while True:
msg = (input()+'\n').encode()
bits = fun.tobits(msg)
ff = fun.toframe(bits,0)
for i in ff:
ct.sendall(i)
time.sleep(0.11)
def listen():
while True:
info = ct.recv(256)
ls = fun.find_sub(info,fun.TAG)
if len(ls) == 2:
info = info[ls[0]+len(fun.TAG)+len(fun.ACK0):ls[1]]
info = fun.unframe(info)
#print(info)
info = fun.get_msg(info)
print(info,end = '')
if __name__ == '__main__':
print("Please input the port")
PORT = int(input())
ct.connect((HOST,PORT))
lis = threading.Thread(target=listen)
wrt = threading.Thread(target = write)
lis.start()
wrt.start()