BOSWatch 3
Python Script to receive and decode German BOS Information with rtl_fm and multimon-NG
 
Loading...
Searching...
No Matches
boswatch.network.broadcast.BroadcastClient Class Reference

BroadcastClient class. More...

Public Member Functions

def __init__ (self, port=5000)
 Create an BroadcastClient instance.
 
def getConnInfo (self, retry=0)
 Get the connection info from server over udp broadcast.
 
def serverIP (self)
 Property to get the server IP after successful broadcast.
 
def serverPort (self)
 Property to get the server Port after successful broadcast.
 

Protected Attributes

 _broadcastPort
 
 _serverIP
 
 _serverPort
 
 _socket
 

Detailed Description

BroadcastClient class.

Constructor & Destructor Documentation

◆ __init__()

def boswatch.network.broadcast.BroadcastClient.__init__ (   self,
  port = 5000 
)

Create an BroadcastClient instance.

    @param port: port to send broadcast packets (5000)
27 def __init__(self, port=5000):
28 r"""!Create an BroadcastClient instance
29
30 @param port: port to send broadcast packets (5000)"""
31 self._broadcastPort = port
32
33 self._serverIP = ""
34 self._serverPort = 0
35
36 self._socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
37 self._socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
38 self._socket.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
39 self._socket.settimeout(3)
40

Member Function Documentation

◆ getConnInfo()

def boswatch.network.broadcast.BroadcastClient.getConnInfo (   self,
  retry = 0 
)

Get the connection info from server over udp broadcast.

    This function will send broadcast package(s)
    to get connection info from the server.

    - send the magic packet <BW-Request> on broadcast address.
    - wait for a <BW-Result> magic packet.
    - extract the connection data from the magic packet and return

    @param retry: Count of retry - 0 is infinite (0)

    @return True or False
41 def getConnInfo(self, retry=0):
42 r"""!Get the connection info from server over udp broadcast
43
44 This function will send broadcast package(s)
45 to get connection info from the server.
46
47 - send the magic packet <BW-Request> on broadcast address.
48 - wait for a <BW-Result> magic packet.
49 - extract the connection data from the magic packet and return
50
51 @param retry: Count of retry - 0 is infinite (0)
52
53 @return True or False"""
54 sendPackages = 0
55 while sendPackages < retry or retry == 0:
56 try:
57 logging.debug("send magic <BW3-Request> as broadcast - Try: %d", sendPackages)
58 self._socket.sendto("<BW3-Request>".encode(), ('255.255.255.255', self._broadcastPort))
59 sendPackages += 1
60 payload, address = self._socket.recvfrom(1024)
61 payload = str(payload, "UTF-8")
62
63 if payload.startswith("<BW3-Result>"):
64 logging.debug("received magic <BW3-Result> from: %s", address[0])
65 self._serverIP = address[0]
66 self._serverPort = int(payload.split(";")[1])
67 logging.info("got connection info from server: %s:%d", self._serverIP, self._serverPort)
68 return True
69 except socket.timeout: # nothing received - retry
70 logging.debug("no magic packet received")
71 logging.warning("cannot fetch connection info after %d tries", sendPackages)
72 return False
73

◆ serverIP()

def boswatch.network.broadcast.BroadcastClient.serverIP (   self)

Property to get the server IP after successful broadcast.

75 def serverIP(self):
76 r"""!Property to get the server IP after successful broadcast"""
77 return self._serverIP
78

◆ serverPort()

def boswatch.network.broadcast.BroadcastClient.serverPort (   self)

Property to get the server Port after successful broadcast.

80 def serverPort(self):
81 r"""!Property to get the server Port after successful broadcast"""
82 return self._serverPort
83
84

Field Documentation

◆ _broadcastPort

boswatch.network.broadcast.BroadcastClient._broadcastPort
protected

◆ _serverIP

boswatch.network.broadcast.BroadcastClient._serverIP
protected

◆ _serverPort

boswatch.network.broadcast.BroadcastClient._serverPort
protected

◆ _socket

boswatch.network.broadcast.BroadcastClient._socket
protected