-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathFreeSharedCockpitUDPSenderMaster.py
More file actions
56 lines (46 loc) · 1.3 KB
/
FreeSharedCockpitUDPSenderMaster.py
File metadata and controls
56 lines (46 loc) · 1.3 KB
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
import socket
import pickle
import threading
import os
#MASTER
host = '192.168.1.102'
inip = '0.0.0.0'
inport = 49000
outport = 49001
'''SLAVE
host = '192.168.1.115'
inip = '0.0.0.0'
inport = 49001
outport = 49000
'''
filename = 'C:/2.fll'
try:
os.remove(filename)
except OSError:
print('Cant remove file!')
def udpRx():
while 1:
try:
infile = open('C:/1.fll', 'r')
PickledTx = infile.read()
except:
print('read error')
s1 = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s1.connect((host, outport), )
s1.sendto(PickledTx, (host, outport))
s1.close()
s2 = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s2.settimeout(0.04)
try:
s2.bind((inip, inport), )
PickledRx = s2.recvfrom(1024)
try:
outfile = open('C:/2.fll', 'w')
outfile.write(PickledRx[0])
print(PickledRx[0])
except:
print('Unable to write')
except(socket.timeout, IndexError):
print('UDP no data received from Port: ' + str(inport))
s2.close()
udpthread = threading.Thread(target=udpRx).start() # export data and receive data every cycle