provide a socket timeout parameter so apps don't get hung up in socket.recv

section_mults
bmo 2018-02-04 20:24:06 -08:00
rodzic 83e1d01340
commit cb71674f8b
2 zmienionych plików z 7 dodań i 2 usunięć

Wyświetl plik

@ -47,8 +47,12 @@ class SimpleServer(object):
self.sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)
def rx_packet(self):
pkt, addr_port = self.sock.recvfrom(self.MAX_BUFFER_SIZE) # buffer size is 1024 bytes
return(pkt, addr_port)
try:
pkt, addr_port = self.sock.recvfrom(self.MAX_BUFFER_SIZE) # buffer size is 1024 bytes
return(pkt, addr_port)
except socket.timeout:
logging.debug("rx_packet: socket.timeout")
return (None, None)
def send_packet(self, addr_port, pkt):
bytes_sent = self.sock.sendto(pkt,addr_port)

Wyświetl plik

@ -6,6 +6,7 @@ import pywsjtx.extra.simple_server
s = pywsjtx.extra.simple_server.SimpleServer('127.0.0.1','2237',timeout=2.0)
while True:
(pkt, addr_port) = s.rx_packet()
if (pkt != None):
the_packet = pywsjtx.WSJTXPacketClassFactory.from_udp_packet(addr_port, pkt)