def start_client(args): trace.writeline('start client') sckt = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) while True: print 'Type message >', sys.stdout.flush() msg = raw_input() if msg.lower() == 'q': break sckt.sendto(msg, (args.host, args.port)) msg, addr = sckt.recvfrom(1024) trace.writeline("Received ->", msg, addr)
def send_mail_via_nifty(to_addr, subject, body, key): from_addr = "*****@*****.**" account = cipherpickle.loads(__nifty, key) msg = __create_message(from_addr, to_addr, subject, body) smtp = smtplib.SMTP("smtp.nifty.com", 587) # smtp.ehlo() # smtp.starttls() smtp.ehlo() smtp.login(account["username"], account["password"]) smtp.sendmail(from_addr, [to_addr], msg.as_string()) smtp.close() trace.watch(msg) trace.writeline(str(msg))
def start_server(args): trace.writeline('start server') sckt = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sckt.bind((args.host, args.port)) sckt.settimeout(5) while True: trace.writeline('wait...') try: msg, addr = sckt.recvfrom(1024) except socket.timeout as e: continue trace.writeline("Received ->", msg, addr) trace.writeline("Send ACK to", addr) sckt.sendto('ACK', addr)