-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreceiver_client.py
executable file
·68 lines (58 loc) · 1.75 KB
/
receiver_client.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/python3
import time
import socket # Import socket module
import sys
import termios
import struct
import fcntl
import argparse
import os
# Setup terminal window size
NROWS = 50
NCOLS = 200
def main():
parser = argparse.ArgumentParser('Socket Receiver for displaying text to termina')
parser.add_argument('host', help='IP address to get stream from')
parser.add_argument('port', help='Port to connect on')
args = parser.parse_args()
host = args.host
port = int(args.port)
s = socket.socket()
# change tty/pty setting
winsize = struct.pack("HHHH", NROWS, NCOLS, 0, 0)
fcntl.ioctl(sys.stdin, termios.TIOCSWINSZ, winsize)
# change actual window size
sys.stdout.write("\x1b[8;{rows};{cols}t".format(rows=NROWS, cols=NCOLS))
while True:
input('Connect?')
try:
s.connect((host, port))
print('Connected')
break
except socket.error as e:
print('Failed ' + str(e))
while True:
prev_time = time.time()
try:
if time.time() - prev_time > 1:
prev_time = time.time()
sys.stdout.write('\033[2J')
temp = s.recv(400).decode('utf-8')
sys.stdout.write(temp)
if temp is None:
break
except (KeyboardInterrupt,socket.error):
s.close # Close the socket when done
s.shutdown(socket.SHUT_RD)
print('closed')
break
if __name__ == '__main__':
os.system('xdotool key ctrl+minus')
os.system('xdotool key ctrl+minus')
try:
main()
except:
pass
finally:
os.system('xdotool key ctrl+plus')
os.system('xdotool key ctrl+plus')