1# Copyright Maciej Sobczak 2008-2019. 2# This file is part of YAMI4. 3# 4# YAMI4 is free software: you can redistribute it and/or modify 5# it under the terms of the GNU General Public License as published by 6# the Free Software Foundation, either version 3 of the License, or 7# (at your option) any later version. 8# 9# YAMI4 is distributed in the hope that it will be useful, 10# but WITHOUT ANY WARRANTY; without even the implied warranty of 11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12# GNU General Public License for more details. 13# 14# You should have received a copy of the GNU General Public License 15# along with YAMI4. If not, see <http://www.gnu.org/licenses/>. 16 17import sys 18import yami 19 20argc = len(sys.argv) 21if argc != 2 and argc != 5: 22 print("need 1 or 4 parameters:") 23 print(" - server address") 24 print(" - outgoing high water mark") 25 print(" - outgoing low water mark") 26 print(" - number of iterations") 27 print("If only server address is given," + 28 " the limits will have default values" 29 " and the loop will be infinite") 30 exit() 31 32server_address = sys.argv[1] 33num_of_iterations = -1 34 35options = {} 36if argc == 5: 37 try: 38 outgoing_high_water_mark = int(sys.argv[2]) 39 outgoing_low_water_mark = int(sys.argv[3]) 40 num_of_iterations = int(sys.argv[4]) 41 except ValueError: 42 print("invalid arguments") 43 exit() 44 45 options[yami.Agent.OptionNames.OUTGOING_HIGH_WATER_MARK] = \ 46 outgoing_high_water_mark 47 options[yami.Agent.OptionNames.OUTGOING_LOW_WATER_MARK] = \ 48 outgoing_low_water_mark 49 50 51try: 52 with yami.Agent(options) as client_agent: 53 54 index = 1 55 while True: 56 params = {"index":index} 57 58 client_agent.send_one_way( 59 server_address, "object", "message", params) 60 61 print("posted message", index) 62 63 if num_of_iterations > 0: 64 if index == num_of_iterations: 65 break 66 67 index = index + 1 68 69except Exception as e: 70 print("error:", e) 71