Skip to content

Commit

Permalink
Fix reconnection
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelchang committed Feb 13, 2018
1 parent cd1ab95 commit 120126f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
23 changes: 12 additions & 11 deletions src/client_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,18 @@ def run(self):
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 65535)
self.socket.setsockopt(socket.SOL_IP, 10, 0)
self.socket.connect((self.host, self.port))
self.socket.settimeout(1.0)
while True:
try:
self.socket.sendto("CONNECT:{}:{}".format(self.private_key, self.name), (self.host, self.port))
reply, addr = self.socket.recvfrom(64)
if reply == "HANDSHAKE":
print "[{}-canopy-client] Connected to server.".format(self.name)
break
except socket.timeout:
print "[{}-canopy-client] Connection timed out. Retrying...".format(self.name)
continue
self.socket.sendto("CONNECT:{}:{}".format(self.private_key, self.name), (self.host, self.port))
# self.socket.settimeout(1.0)
# while True:
# try:
# self.socket.sendto("CONNECT:{}:{}".format(self.private_key, self.name), (self.host, self.port))
# reply, addr = self.socket.recvfrom(64)
# if reply == "HANDSHAKE":
# print "[{}-canopy-client] Connected to server.".format(self.name)
# break
# except socket.timeout:
# print "[{}-canopy-client] Connection timed out. Retrying...".format(self.name)
# continue
self.socket.setblocking(1)
for topic, msg_type, trusted in self.broadcasting:
if topic[0] != "/":
Expand Down
1 change: 0 additions & 1 deletion src/receiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ def process_message(self, payload):
frmt = "%ds" % size[0]
unpacked = struct.unpack('=I' + frmt, decompressed)
data = json.loads(unpacked[1])
print data
self.values[data["Topic"]] = data
except:
pass

0 comments on commit 120126f

Please sign in to comment.