""" sender.py: This is a python simpl text-based sender. Usage: python3 sender.py myName receiverName """ # import required modules import sys import csimpl # initialize necessary variables sName = sys.argv[1] rName = sys.argv[2] # create an instance of Simpl nee = csimpl.Simpl(sName, 1024) if (nee == -1): print ("name attach error-", whatsMyError()) sys.exit(-1) # name locate the receiver program receiverId = nee.nameLocate(rName) if receiverId == -1: print ("name locate error-", nee.whatsMyError()) sys.exit(-1) while True: try: line = input("-> ") except EOFError: break else: if line[0] == '?': print("enter s n1,n2,n3 to get sum") print("enter q to quit") if line[0] == 's': ss=line.split() s=ss[1].split(",") val1=int(s[0]) val2=int(s[1]) val3=int(s[2]) print("var=%d %d %d" %(val1, val2, val3)) # compose the message you wish # to send based on the value of # the token inToken=10 print ("token = %d" %inToken) nee.packMsg(nee.BIN, "iiii",inToken,val1,val2,val3) # send the message retVal = nee.send(receiverId) if retVal == -1: print ("send error-",nee.whatsMyError()) sys.exit(-1) # unpack the reply message outToken, sum = nee.unpackMsg(nee.BIN, "ii") if outToken == 10: print ("reply token=%d sum=%d" %(outToken,sum) ) else: print ("reply token=%d" %outToken ) elif line[0] == "q": break print("done")