#usage: python server.py (servername) os.system('clear') # Hard coded a list of servers & ports SERVERS = {} SERVERS["s1"] = ('localhost', 1000) SERVERS["s2"] = ('localhost', 2000) NUM_SERVERS = 2 # Dict of integers DATA_LIB = {} TOTAL_ORDERING = Integer('server_order') COUNTER = Integer('meow') COUNTER.set(0) # Server name of this server THIS_SERVER = sys.argv[1] # The waiting queue for this server # the key is the HOST,PORT of the client # then it gives back an array: [jobNumber, remaining waiting servers, actual commands] JOB_QUEUE = {} # locks lock = threading.Lock() class ClientRequestHandler(SocketServer.BaseRequestHandler): def handle(self): data = self.request[0].strip()
# to create a binary file use: dd if=/dev/random of=file2.bin bs=1m count=200 host = sys.argv[1] try: port = int(sys.argv[2]) except StandardError: port = 5006 address = (host,port) BLOCK_SIZE = 1024 INDEX_SIZE = 8 buf = BLOCK_SIZE - INDEX_SIZE # NO LONGER NEEDED BECAUSE THIS IS NOT SERIALIZED DATA - WE ARE NOT SENDING IT # filename = sys.argv[2] # example_message = "Start." # client_socket.sendto(example_message, address) integer_by = Integer(73) integer_by.set(37) data_by = integer_by # data_by = [ { 'a':'A', 'b':2, 'c':3.0 } ] # print 'DATA:', # pprint.pprint(data_by) data_string_by = pickle.dumps(data_by) client_socket.sendto(data_string_by, address) # print 'PICKLE:', data_string_by client_socket.close()