Beispiel #1
0
    def send_message(self, msg: Message):
        payload = msg.to_json()

        receiver_id = msg.get_receiver_id()

        if receiver_id == 0:
            channel_url = '{}:{}'.format('67.199.133.186',
                                         str(50000 + receiver_id))
        elif receiver_id == 1:
            channel_url = '{}:{}'.format('67.199.133.186',
                                         str(50000 + receiver_id))
        elif receiver_id == 2:
            channel_url = '{}:{}'.format('117.161.90.229',
                                         str(50000 + receiver_id))

        channel = grpc.insecure_channel(channel_url)
        stub = grpc_comm_manager_pb2_grpc.gRPCCommManagerStub(channel)

        request = grpc_comm_manager_pb2.CommRequest()
        logging.info("sending message to port " +
                     str(50000 + int(msg.get_receiver_id())))

        request.client_id = self.client_id

        request.message = payload

        stub.sendMessage(request)
        logging.info("sent")
Beispiel #2
0
    def send_message(self, msg: Message):
        """
            [server]
            sending message topic (publish): serverID_clientID
            receiving message topic (subscribe): clientID

            [client]
            sending message topic (publish): clientID
            receiving message topic (subscribe): serverID_clientID

        """
        if self.client_id == 0:
            # server
            receiver_id = msg.get_receiver_id()
            topic = self._topic + str(0) + "_" + str(receiver_id)
            logging.info("topic = %s" % str(topic))
            payload = msg.to_json()
            self._client.publish(topic, payload=payload)
            logging.info("sent")
        else:
            # client
            self._client.publish(self._topic + str(self.client_id),
                                 payload=msg.to_json())
Beispiel #3
0
    def send_message(self, msg: Message):
        payload = msg.to_json()

        receiver_id = msg.get_receiver_id()

        # lookup ip of receiver from self.ip_config table
        receiver_ip = self.ip_config[str(receiver_id)]
        channel_url = '{}:{}'.format(receiver_ip, str(50000 + receiver_id))

        channel = grpc.insecure_channel(channel_url, options=self.opts)
        stub = grpc_comm_manager_pb2_grpc.gRPCCommManagerStub(channel)

        request = grpc_comm_manager_pb2.CommRequest()
        logging.info("sending message to port " + str(50000 + receiver_id))

        request.client_id = self.client_id

        request.message = payload

        stub.sendMessage(request)
        logging.info("sent")
        channel.close()