func listenOutage(conn *net.UDPConn) { for { b := make([]byte, 256) _, _, err := conn.ReadFromUDP(b) fmt.Println("read", string(b)) t, m, err := message.DecodeClientToClientMessage(b) if err != nil { log.Println("[Client] Can't decode message", string(b)) } switch t { case message.VOTE_T: // Start voting if !inVotingProcess { startVotingAlgorithm() } address := m.VoteMessage.Number fmt.Println("Got this address", address) if address != myAddress { // Add Adress to list of known address otherClientsAddress[address] = true fmt.Println("Known address", otherClientsAddress) } case message.COORDINATOR_T: Newaddr := m.CoordinatorMessage.Address fmt.Println("Coordinator", Newaddr) stopVotingProcess() } log.Println("[Client] Got", m) } }
func listen(conn *net.UDPConn) { for { b := make([]byte, 256) _, _, err := conn.ReadFromUDP(b) check(err) fmt.Println("read", string(b)) t, m, err := message.DecodeClientToClientMessage(b) if err != nil { log.Println("[Client] Can't decode message", string(b)) } switch t { case message.VOTE_T: address := m.VoteMessage.Number fmt.Println("Got this address", address) if address != myAddress { // Add Adress to list of known address knownAddresess[address] = true fmt.Println("Known address", knownAddresess) } case message.COORDINATOR_T: Newaddr := m.CoordinatorMessage.Address fmt.Println("Coordinator", Newaddr) } log.Println("[Client] Got", m) } }