Commit 0ea78a83 authored by 's avatar
Browse files

ça a l'air bien parti, mais ils arrivent pas à communiquer entre eux... NB :...

ça a l'air bien parti, mais ils arrivent pas à communiquer entre eux... NB : en python2, il faut commenter les lignes où je split le body sur les guillemets, en python3, faut les garder
parent 9bbdc320
...@@ -32,32 +32,41 @@ class LamportClient: ...@@ -32,32 +32,41 @@ class LamportClient:
self.queue = list(); self.queue = list();
self.times = {n:0 for n in range(1,clients+1)} self.times = {n:0 for n in range(1,clients+1)}
self.mustFree = False
self.mustRequest = True
self.channel = pika.BlockingConnection( self.channel = pika.BlockingConnection(
pika.ConnectionParameters(host='localhost') pika.ConnectionParameters(host='localhost')
).channel() ).channel()
self.channel.basic_qos(prefetch_count=1) self.channel.basic_qos(prefetch_count=1)
self.channel.exchange_declare(exchange="lamport", exchange_type="fanout") self.channel.exchange_declare(
self.channel.exchange_declare(exchange="lamport_init", exchange_type="fanout") exchange="lamport", exchange_type="fanout")
self.channel.exchange_declare(
exchange="lamport_init", exchange_type="fanout")
self.reception = self.channel.queue_declare(exclusive=True).method.queue self.reception = self.channel.queue_declare(
self.init_reception = self.channel.queue_declare(exclusive=True).method.queue exclusive=True).method.queue
self.init_reception = self.channel.queue_declare(
exclusive=True).method.queue
self.channel.queue_bind(exchange = "lamport", queue = self.reception) self.channel.queue_bind(
self.channel.queue_bind(exchange = "lamport_init", queue = self.init_reception) exchange = "lamport", queue = self.reception)
self.channel.queue_bind(
self.mustFree = False exchange = "lamport_init", queue = self.init_reception)
self.mustRequest = True
def run(self): def run(self):
print("I am {} of {} sites".format(self.id, len(list(self.times.keys())))) print("I am {} of {} sites".format(
self.id, len(list(self.times.keys()))))
if self.channel.connection.is_open: if self.channel.connection.is_open:
print("Well connected to server") print("Well connected to server")
self.channel.basic_consume(self.initializeCycle, self.init_reception) self.channel.basic_consume(
self.initializeCycle, self.init_reception)
self.channel.basic_publish(exchange="lamport_init", body = "{} says : Hello World!".format(self.id), routing_key='') self.channel.basic_publish(
exchange="lamport_init", body = "{} says : Hello World!".format(self.id), routing_key='')
print("saying hello to the world") print("saying hello to the world")
self.channel.start_consuming() self.channel.start_consuming()
...@@ -82,7 +91,7 @@ class LamportClient: ...@@ -82,7 +91,7 @@ class LamportClient:
#client.free() #client.free()
def initializeCycle(self, channel, method, properties, body): def initializeCycle(self, channel, method, properties, body):
_,body,_ = str(body).split("'") #_,body,_ = str(body).split("'")
arrival_id = int(body.split(" ")[0]) arrival_id = int(body.split(" ")[0])
self.n_clients_here += 1 self.n_clients_here += 1
...@@ -143,7 +152,7 @@ class LamportClient: ...@@ -143,7 +152,7 @@ class LamportClient:
def when_receive(self, channel, method, properties, body): def when_receive(self, channel, method, properties, body):
body = str(body) body = str(body)
_,body,_ = body.split("'") #_,body,_ = body.split("'")
print("received {}".format(body)) print("received {}".format(body))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment