-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
51 lines (43 loc) · 1.33 KB
/
server.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
import os
from socket import *
from struct import pack
class ServerProtocol:
def __init__(self):
self.socket = None
def listen(self, server_ip, server_port):
self.socket = socket(AF_INET, SOCK_STREAM)
self.socket.bind((server_ip, server_port))
self.socket.listen(1)
def send_image(self, iq_data):
try:
while True:
(connection, addr) = self.socket.accept()
try:
length = pack('>Q', len(iq_data))
connection.send(length)
connection.sendall(iq_data)
finally:
connection.shutdown(SHUT_WR)
connection.close()
print("File Transfer Complete")
break
finally:
self.close()
return 0
def close(self):
self.socket.close()
self.socket = None
# could handle a bad ack here, but we'll assume it's fine.
if __name__ == '__main__':
sp = ServerProtocol()
cmd = "rtl_sdr -f 88300000 -g 28.4 -s 2500000 -n 25000000 pynqradio.dat"
os.system(cmd)
print("Server captured Radio Data")
print("Server is listening...")
sp.listen('', 12345)
iq_data = None
#with open('pynq1.dat', 'rb') as iq:
with open('pynqradio.dat', 'rb') as iq:
iq_data = iq.read()
assert(len(iq_data))
sp.send_image(iq_data)