Skip to content

Commit

Permalink
add an option to send a 'hello' message to a client as soon as it con…
Browse files Browse the repository at this point in the history
…nects
  • Loading branch information
JoelBender committed May 12, 2017
1 parent fe08d71 commit a538bd7
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions samples/TCPServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
SERVER_PORT = int(os.getenv('SERVER_PORT', 9000))
IDLE_TIMEOUT = int(os.getenv('IDLE_TIMEOUT', 0)) or None

# globals
args = None

#
# EchoMaster
#
Expand All @@ -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)

Expand All @@ -67,6 +76,8 @@ def indication(self, add_actor=None, del_actor=None, actor_error=None, error=Non
#

def main():
global args

# parse the command line arguments
parser = ArgumentParser(description=__doc__)
parser.add_argument(
Expand All @@ -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")
Expand Down

0 comments on commit a538bd7

Please sign in to comment.