1
0
mirror of https://github.com/JoelBender/bacpypes synced 2025-09-28 22:15:23 +08:00

add an option to send a 'hello' message to a client as soon as it connects

This commit is contained in:
Joel Bender 2017-05-11 23:45:21 -04:00
parent fe08d71650
commit a538bd7f45

View File

@ -25,6 +25,9 @@ SERVER_HOST = os.getenv('SERVER_HOST', 'any')
SERVER_PORT = int(os.getenv('SERVER_PORT', 9000))
IDLE_TIMEOUT = int(os.getenv('IDLE_TIMEOUT', 0)) or None
# globals
args = None
#
# EchoMaster
#
@ -51,9 +54,15 @@ class MiddleManASE(ApplicationServiceElement):
and socket errors.
"""
def indication(self, add_actor=None, del_actor=None, actor_error=None, error=None):
global args
if add_actor:
if _debug: MiddleManASE._debug("indication add_actor=%r", add_actor)
# it's connected, maybe say hello
if args.hello:
self.elementService.indication(PDU(b'Hello, world!\n', destination=add_actor.peer))
if del_actor:
if _debug: MiddleManASE._debug("indication del_actor=%r", del_actor)
@ -67,6 +76,8 @@ bacpypes_debugging(MiddleManASE)
#
def main():
global args
# parse the command line arguments
parser = ArgumentParser(description=__doc__)
parser.add_argument(
@ -84,6 +95,11 @@ def main():
help="idle connection timeout",
default=IDLE_TIMEOUT,
)
parser.add_argument(
"--hello", action="store_true",
default=False,
help="send a hello message to a client when it connects",
)
args = parser.parse_args()
if _debug: _log.debug("initialization")