new
This commit is contained in:
26
server/DynReceiver.py
Normal file
26
server/DynReceiver.py
Normal file
@ -0,0 +1,26 @@
|
||||
import threading
|
||||
import socket
|
||||
import Queue
|
||||
import time
|
||||
import Event
|
||||
|
||||
|
||||
|
||||
class DynReceiver(threading.Thread):
|
||||
def __init__(self, dynRecvAddr, queue):
|
||||
threading.Thread.__init__(self)
|
||||
self.dynRecvAddr = dynRecvAddr
|
||||
self.queue = queue
|
||||
self.setDaemon(True)
|
||||
|
||||
def run(self):
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
s.bind(self.dynRecvAddr)
|
||||
|
||||
while True:
|
||||
data, address = s.recvfrom(256)
|
||||
try:
|
||||
self.queue.put_nowait(Event.Event(address, data, int(time.time())))
|
||||
except Queue.Full:
|
||||
print "Event %s from %s dropped" % (data, str(address))
|
||||
|
Reference in New Issue
Block a user