Ejemplo n.º 1
0
    def setUp(self):
        self.client1 = IvyServer("client1")
        self.client2 = IvyServer("client2")

        self.client1.start()
        self.client2.start()

        self.message = None
Ejemplo n.º 2
0
 def __init__(self, mode, adresse, nom):
     self._mode = mode
     IvyServer.__init__(self, nom)
     self.name = "Agent Reseau"
     self.start(adresse)
     self.bind_msg(self.receptionGrille, '^grille=(.*)')
     self.bind_msg(self.receptionCasesADetruire, '^cases=(.*)')
     self.bind_msg(self.receptionDelai, '^delai=(.*)')
     self.bind_msg(self.gererEcho, 'echo')
     self.bind_msg(self.receptionChangementTour, 'changementTour')
     self.bind_msg(self.receptionFinPartie, 'finPartie')
Ejemplo n.º 3
0
    def handle_new_client(self, client):
        IvyServer.handle_new_client(self, client)

        found = False
        for c in self.get_clients():
            if client.agent_name == c:
                if found:
                    client.send_die_message(
                    )  # Un autre client avec le même nom existe déjà.
                else:
                    found = True
Ejemplo n.º 4
0
def IvyInit(agent_name,
            ready_msg=None,
            main_loop_type_ignored=0,
            on_cnx_fct=void_function,
            on_die_fct=void_function):
    """
  Initializes the module. This method should be called exactly once before any
  other method is called.
  """
    global _IvyServer
    assert _IvyServer is None
    from ivy.ivy import IvyServer
    _IvyServer = IvyServer(agent_name, ready_msg, on_cnx_fct, on_die_fct)
Ejemplo n.º 5
0
 def __init__(self, name):
     IvyServer.__init__(self, 'MonAgentPython')
     self.name = name
     self.start('127.255.255.255:2010')
     self.bind_msg(self.handle_hello, '^hello (.*)')
Ejemplo n.º 6
0
 def __init__(self, name):
   IvyServer.__init__(self, name)
   self.name = name
   self.start('127.255.255.255:2010')
   time.sleep(1)
Ejemplo n.º 7
0
 def __init__(self):
   IvyServer.__init__(self,'CAMERA')
   self.name = 'CAMERA'
   self.start('192.168.1.255:2010')       
   self.bind_msg(self.handle_demande_pos, 'DEMANDE POSITION')
Ejemplo n.º 8
0
 def __init__(self, agent_name: str, state) -> None:
     IvyServer.__init__(self, agent_name, f'connect={state.name}')
Ejemplo n.º 9
0
 def __init__(self, agent_name, msg='hello world'):
     IvyServer.__init__(self, agent_name)
     self.start()
     self.bind_msg(self.on_hello, "hello world")
Ejemplo n.º 10
0
 def __init__(self, name):
     ivylogger.setLevel(logging.WARN)
     self.name = name
     IvyServer.__init__(self, self.name)
Ejemplo n.º 11
0
class EndToEndTestCase(BaseTestCase):
    def setUp(self):
        self.client1 = IvyServer("client1")
        self.client2 = IvyServer("client2")

        self.client1.start()
        self.client2.start()

        self.message = None

    def setMessageReceived(self, agent, message):
        self.message = message

    def setDirectMessageReceived(self, agent, num_id, message):
        self.message = message

    def testMessageMatches(self):
        """
        Tests that the message is received by client1 when it matches
        the regex.
        """
        self.client1.bind_msg(self.setMessageReceived, "message (.*)")
        self.waitForNetwork()
        self.client2.send_msg("message value")
        self.waitForNetwork()

        self.assertEqual(self.message, "value")

    def testMessageDoesntMatch(self):
        """
        Tests that no message is sent when the regex doesn't match.
        """
        self.client1.bind_msg(self.setMessageReceived, "foo (.*)")
        self.waitForNetwork()
        self.client2.send_msg("bar value")
        self.waitForNetwork()

        self.assertEqual(self.message, None)

    def testDirectMessage(self):
        """
        Tests that direct messages can be sent.
        """
        self.client1.bind_direct_msg(self.setDirectMessageReceived)
        self.waitForNetwork()
        self.client2.send_direct_message("client1", 1, "secret message")
        self.waitForNetwork()

        self.assertEqual(self.message, "secret message")

    def testListMessage(self):
        """
        Tests that lists can be sent as direct messages (an extension 
        of the ivy protocol implemented on Python only).
        """
        self.client1.bind_direct_msg(self.setDirectMessageReceived)
        self.waitForNetwork()
        self.client2.send_direct_message("client1", 1, ["list", "message"])
        self.waitForNetwork()

        self.assertEqual(self.message, ["list", "message"])

    def tearDown(self):
        self.client1.stop()
        self.client2.stop()
        self.waitForNetwork()