2010-09-19, 02:07
SOLVED: For those interested. I solved this by initiating it via the autoexec.py located in your userdata dir
Anyone know how to go about adding/using a UDP Sender/Listener to a plugin script without it locking up the script?
I have the code built to do the actual sending and listening and it works very well but it blocks any use of the plugin until it finishes which in this case, it never would because thats the point.
Any way to have it start in a non-blocking fashion? and report back to the main script that started it what it has recieved?
UPDATE>>> I have tried the following in my plugin but neither seem to work... ::::
subprocess.Popen("/home/user/sendUDP.py")
or
subprocess.Popen("python /home/user/sendUDP.py", shell=True)
This is the Server (Receiver) Portion:
This is the Client (Sender) Snippet
Anyone know how to go about adding/using a UDP Sender/Listener to a plugin script without it locking up the script?
I have the code built to do the actual sending and listening and it works very well but it blocks any use of the plugin until it finishes which in this case, it never would because thats the point.
Any way to have it start in a non-blocking fashion? and report back to the main script that started it what it has recieved?
UPDATE>>> I have tried the following in my plugin but neither seem to work... ::::
subprocess.Popen("/home/user/sendUDP.py")
or
subprocess.Popen("python /home/user/sendUDP.py", shell=True)
This is the Server (Receiver) Portion:
Code:
import os, socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind(('0.0.0.0', port)) ## You also specify a specific intf, like '255.255.255.255' for Bcast or '127.0.0.1' for localhost...
s.setblocking(0)
while True:
result = select.select([s],[],[])
msg = result[0][0].recv(bufferSize)
print msg
Code:
from time import time, ctime, sleep
import os
import socket
BEATWAIT = 30
#broadcasts "MAV_Master @ <hostip>" to all machines on the local subnet, on port 8286
while 1:
outsock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
outsock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
bcast = "255.255.255.255"
msg = "FOO_Master @ 192.168.1.1"
port = 8286
outsock.sendto(msg, ('255.255.255.255', 8286))
sleep(BEATWAIT)