RoboidControl-python/SiteServer.py
2024-12-21 14:58:38 +01:00

23 lines
763 B
Python

from .Participant import Participant
from .Thing import Thing
from . import Messages
import select
class SiteServer(Participant):
def __init__(self, ipAddress, port):
super().__init__(ipAddress, port)
self.udpSocket.setblocking(0)
def Update(self, currentTime):
ready_to_read, _, _ = select.select([self.udpSocket], [], [], 0.1) # Timeout of 0.1 seconds
if ready_to_read:
data, addr = self.udpSocket.recvfrom(1024)
self.ReceiveData(data)
return super().Update(currentTime)
def ProcessNetworkIdMsg(self, msg):
self.networkId = msg.networkId
msg = Messages.ThingMsg(self.networkId, next(iter(Thing.allThings)))
msg.SendTo(self)