def put(key, val): seq = next_seq_no() msg = ' '.join([UUID, "put", str(seq), val]) peer2peer.publish(Ps, "dbd", msg) msgs = peer2peer.recv(Ps) print "MP", msgs return msgs[2]
def main(sub_to, pub_to, channel_in, channel_out): ws1 = peer2peer.conn(sub_to) peer2peer.subscribe(ws1, channel_in) ws2 = peer2peer.conn(pub_to) while 1: msgs = peer2peer.recv(ws1) msg = msgs[2] peer2peer.publish(ws2, channel_out, msg) time.sleep(0.2) pass
def connect(): global Ps Ps = peer2peer.conn() peer2peer.subscribe(Ps, "dbd " + UUID) peer2peer.publish(Ps, "dbd", UUID + " hola 200") msgs = peer2peer.recv(Ps) print "M", msgs print(get("key")) uuidx = str(uuid.uuid4()) print(put("newkey", "newval." + uuidx)) print(get("nope")) print(get("newkey")) #while 1: # msgs = peer2peer.recv(Ps) # print "M", msgs # time.sleep(0.2) # pass pass
def main(): while 1: print "BEFORE" try: peer2peer.subscribe(Ps, 'dbd') while 1: msgs = peer2peer.recv(Ps) msg = msgs[2] arr = msg.split() print "ARR", arr if arr[1] == 'hola': peer2peer.publish(Ps, arr[0], arr[2] + " YO!") elif arr[1] == 'put': db.Put(arr[2], arr[3]) peer2peer.publish(Ps, arr[0], arr[2] + " OK") elif arr[1] == 'get': try: result = db.Get(arr[3]) peer2peer.publish(Ps, arr[0], arr[2] + ' ' + result) except KeyError: peer2peer.publish(Ps, arr[0], arr[2]) else: print "ERROR, DONT KNOW HOW TO DO THAT" pass time.sleep(0.2) except: tb.print_exc() print "ERR" time.sleep(1) try: connect() except: print "ERR2" tb.print_exc() pass pass print "AFTER"
def get(key): seq = next_seq_no() peer2peer.publish(Ps, "dbd", UUID + " get 50 " + key) msgs = peer2peer.recv(Ps) print "MG", msgs return msgs[2]