private void RecebidadeMensagemDoLider(bool recebi) { if (!recebi && !ControleDeProcessos.VerificaSeTemLider()) { this.lider = true; Console.WriteLine("Processo " + this.id.ToString() + " virou lider."); } else { if (ControleDeProcessos.VerificaSeTemLider()) { this.lider = false; Console.WriteLine("Processo " + this.id.ToString() + " nao virou lider."); } else { this.lider = true; Console.WriteLine("Processo " + this.id.ToString() + " virou lider."); } } }
private bool InsereProcessoNoControle() { try { this.id = this.PegaId(); this.ip = this.PegaIp(); this.porta = PegaPorta(); IPAddress m_GrpAddr = IPAddress.Parse("FF01::1"); this.udpClient = new UdpClient(this.porta, AddressFamily.InterNetworkV6) { EnableBroadcast = true }; this.udpClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); IPv6MulticastOption ipv6MulticastOption = new IPv6MulticastOption(m_GrpAddr); IPAddress group = ipv6MulticastOption.Group; long interfaceIndex = ipv6MulticastOption.InterfaceIndex; IPv6MulticastOption ipv6MulticastOption2 = new IPv6MulticastOption(group, interfaceIndex); group = ipv6MulticastOption2.Group; interfaceIndex = ipv6MulticastOption2.InterfaceIndex; this.udpClient.JoinMulticastGroup((int)interfaceIndex, group); this.ipe = new IPEndPoint(m_GrpAddr, 2000); ControleDeProcessos.InsereProcessoNoControle(this); return(true); } catch (Exception e) { Console.WriteLine(e.ToString()); return(false); } }
private int PegaPorta() { return(ControleDeProcessos.PegaPorta()); }
private IPAddress PegaIp() { return(IPAddress.Parse(ControleDeProcessos.PegaIp())); }
private int PegaId() { return(ControleDeProcessos.PegaIdParaProcesso()); }