UDPclient - receiving.start() r def sendstuff(): while 1:...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 # Assignment 5, CSCI 4211 # Ben Sprague, 3296712 # UDP Client #!/soft/python-2.4-bin/python import socket, sys, os, threading host = sys.argv[1] port = int(sys.argv[2]) sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) def main(): #while 1: sock.connect( (host, port) ) sending = threading.Thread(target = sendstuff, name = 'sendthis') receiving = threading.Thread(target = recvstuff, name = 'recvthis') sending.start()
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: receiving.start() r def sendstuff(): while 1: try: data = sys.stdin.readline() sock.sendall(data) if data == "exit\n": sock.close() break except (KeyboardInterrupt, SystemExit): raise except: continue def recvstuff(): while 1: try: buf = sock.recv(2048) if not len(buf): print 'Too long of a message!' break sys.stdout.write( buf ) except (KeyboardInterrupt, SystemExit): raise except: continue c main()...
View Full Document

Ask a homework question - tutors are online