def connect_to_cloud_channel(self):
"""
Connect up to the cloud channel with UUID uuid
:param uuid: the UUID of this device. The uuid determines which channel you are connected to
:return:
"""
if self.uuid is None or self.uuid == "":
raise RuntimeError("Must have a valid UUID to connect to the cloud")
if self.connected_to_cloud:
raise RuntimeError("Already Connected to cloud")
yield self.get_channel()
# cool, now set up the websocket connection to that channel
reactor = self._adapter.reactor
print "attempting to connect to", self.channel_uri
self.cloud_factory = CloudLinkWebsocketClientFactory(self, self.channel_uri, reactor=reactor)
self.cloud_factory.protocol = CloudLinkWebsocketClient
self.cloud_factory.continueTrying = True # attempt to reconnect
if self.channel_uri.startswith("wss"):
reactor.connectSSL(self.cloud_factory.host, self.cloud_factory.port, self.cloud_factory, ssl.ClientContextFactory())
else:
reactor.connectTCP(self.cloud_factory.host, self.cloud_factory.port, self.cloud_factory)
评论列表
文章目录