Exemplo n.º 1
0
Arquivo: Node.cs Projeto: roinissan/C-
        //Allows the administrator to send a string message from one machine to another
        //the message must be broken into packets
        //if the node does not recognize the target (the target is not in the routing table)
        //the method returns false
        public bool SendMessage(string sMessage, int iMessageID, int iTarget)
        {
            if (!m_routers.ContainsKey(iTarget))
            {
                return(false);
            }

            MailBoxWriter target_router = m_dNeighbors[m_routers[iTarget]];

            for (int i = 0; i < sMessage.Length; i++)
            {
                PacketMessage new_packet = new PacketMessage(ID, iTarget, iMessageID, sMessage[i], i, sMessage.Length);
                target_router.Send(new_packet);
            }

            return(true);
        }
Exemplo n.º 2
0
Arquivo: Node.cs Projeto: roinissan/C-
 //handles an incoming packet message
 //the message can be directed to the current node or to another node, in which case it should be forwarded
 private void HandlePacketMessage(PacketMessage pmsg)
 {
     if (pmsg.Target != ID)
     {
         m_dNeighbors[GetRouter(pmsg.Target)].Send(pmsg);
     }
     else
     {
         if (!m_messages.ContainsKey(pmsg.MessageID))
         {
             m_messages.Add(pmsg.MessageID, new char[pmsg.Size]);
             for (int i = 0; i < pmsg.Size; i++)
             {
                 m_messages[pmsg.MessageID][i] = '\0';
             }
         }
         bool   is_full = true;
         string message = "";
         m_messages[pmsg.MessageID][pmsg.Location] = pmsg.Packet;
         foreach (char c in m_messages[pmsg.MessageID])
         {
             if (c.Equals('\0'))
             {
                 is_full = false;
             }
         }
         if (is_full)
         {
             foreach (char c in m_messages[pmsg.MessageID])
             {
                 message = message + c;
             }
             Debug.WriteLine(message);
         }
     }
 }