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:
parent
fe08d71650
commit
a538bd7f45
|
@ -25,6 +25,9 @@ SERVER_HOST = os.getenv('SERVER_HOST', 'any')
|
||||||
SERVER_PORT = int(os.getenv('SERVER_PORT', 9000))
|
SERVER_PORT = int(os.getenv('SERVER_PORT', 9000))
|
||||||
IDLE_TIMEOUT = int(os.getenv('IDLE_TIMEOUT', 0)) or None
|
IDLE_TIMEOUT = int(os.getenv('IDLE_TIMEOUT', 0)) or None
|
||||||
|
|
||||||
|
# globals
|
||||||
|
args = None
|
||||||
|
|
||||||
#
|
#
|
||||||
# EchoMaster
|
# EchoMaster
|
||||||
#
|
#
|
||||||
|
@ -51,9 +54,15 @@ class MiddleManASE(ApplicationServiceElement):
|
||||||
and socket errors.
|
and socket errors.
|
||||||
"""
|
"""
|
||||||
def indication(self, add_actor=None, del_actor=None, actor_error=None, error=None):
|
def indication(self, add_actor=None, del_actor=None, actor_error=None, error=None):
|
||||||
|
global args
|
||||||
|
|
||||||
if add_actor:
|
if add_actor:
|
||||||
if _debug: MiddleManASE._debug("indication add_actor=%r", 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 del_actor:
|
||||||
if _debug: MiddleManASE._debug("indication del_actor=%r", del_actor)
|
if _debug: MiddleManASE._debug("indication del_actor=%r", del_actor)
|
||||||
|
|
||||||
|
@ -67,6 +76,8 @@ bacpypes_debugging(MiddleManASE)
|
||||||
#
|
#
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
global args
|
||||||
|
|
||||||
# parse the command line arguments
|
# parse the command line arguments
|
||||||
parser = ArgumentParser(description=__doc__)
|
parser = ArgumentParser(description=__doc__)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
|
@ -84,6 +95,11 @@ def main():
|
||||||
help="idle connection timeout",
|
help="idle connection timeout",
|
||||||
default=IDLE_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()
|
args = parser.parse_args()
|
||||||
|
|
||||||
if _debug: _log.debug("initialization")
|
if _debug: _log.debug("initialization")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user