コード例 #1
0
 def run(self):
     print("Starting Receiver ...")
     while True:
         values = packing.receive_msg(sock)
         message_object = message.GOSSIP_MESSAGE_TYPES.get(
             values['code'], 
             message.MessageGossipNotification
         )
         msg = message_object(values['message'])
         json_str = bytes_to_string(msg.msg)
         print(json_str)
コード例 #2
0
    def __receive(self):
        """
        Receives a new message, unpacks it and forwards it to the assigned controller.

        :returns: The received message object
        """
        msg = packing.receive_msg(self.client_socket)
        if msg['code'] in GOSSIP_MESSAGE_TYPES.keys():
            try:
                message_object = GOSSIP_MESSAGE_TYPES[msg['code']](msg['message'])
            except Exception as e:
                # TODO Don't catch Exception, catch specific decoding exception
                raise GossipMessageFormatException('%s' % e)
        else:
            message_object = MessageOther(msg['code'], msg['message'])

        self.to_controller_queue.put({'type': QUEUE_ITEM_TYPE_RECEIVED_MESSAGE,
                                      'identifier': self.identifier,
                                      'message': message_object})
        return message_object
コード例 #3
0
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import socket
from gossip.util import packing, message

__author__ = 'Anselm Binninger, Ralph Schaumann, Thomas Maier'

try:
    while True:
        sock = socket.socket()
        sock.connect(('localhost', 6001))
        values = packing.receive_msg(sock)
        message_object = message.GOSSIP_MESSAGE_TYPES.get(
            values['code'], message.MessageOther)
        if 500 <= values['code'] < 520:
            print(message_object(values['message']))
        else:
            print(values)
        sock.close()
except Exception as e:
    print('%s' % e)