kopia lustrzana https://github.com/bmo/py-wsjtx
provide a socket timeout parameter so apps don't get hung up in socket.recv
rodzic
83e1d01340
commit
cb71674f8b
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Ładowanie…
Reference in New Issue