UDPserver - if statement =='FALSE...

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 Server #!/soft/python-2.4-bin/python import socket, sys, os host = '' port = int(sys.argv[1]) ssock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) ssock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) ssock.bind( (host, port) ) clientarray = [ssock] while 1: try: message, address = ssock.recvfrom(2048) for entry in clientarray: if entry == address: statement = 'TRUE' break else: statement = 'FALSE'
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: if statement == 'FALSE': clientarray.append(address) chatmessage = '%s: %s' % (address, message) if message == 'exit\n': clientarray.remove(address) elif message == 'Who is chatting?\n': for addr in clientarray: if addr == ssock: continue else: ssock.sendto(addr, address) else: for addr in clientarray: if addr == ssock: continue else: ssock.sendto(chatmessage, addr) except (KeyboardInterrupt, SystemExit): raise except: continue...
View Full Document

This note was uploaded on 04/09/2008 for the course CSCI 4211 taught by Professor Sturtivant during the Spring '08 term at Minnesota.

Ask a homework question - tutors are online