// Send get specified user from prompt and actually send it to the target func Send(ipmsg *goipmsg.IPMSG) { userIdx := []string{} i := 0 m := make(map[int]string) for k, _ := range Users { i++ fmt.Printf("%d %v\n", i, k) userIdx = append(userIdx, strconv.Itoa(i)) m[i] = k } chosen := (&prompter.Prompter{ Choices: userIdx, UseDefault: false, Message: "Choose the user to send message>", IgnoreCase: true, }).Prompt() i, _ = strconv.Atoi(chosen) key := m[i] promptMessage := fmt.Sprintf("Enter message(to %v)", key) message := prompter.Prompt(promptMessage, "") cd := Users[key] addr := cd.Addr cmd := goipmsg.SENDMSG cmd.SetOpt(goipmsg.SECRET) err := ipmsg.SendMSG(addr, message, cmd) if err != nil { panic(err) } fmt.Println("sent SENDMSG") }
// Join sends BR_ENTRY packet to the broadcast address func Join(ipmsg *goipmsg.IPMSG) { addr := brAddr(ipmsg) cmd := goipmsg.BR_ENTRY cmd.SetOpt(goipmsg.BROADCAST) err := ipmsg.SendMSG(addr, ipmsg.Myinfo(), cmd) if err != nil { panic(err) } fmt.Println("sent BR_ENTRY") }
func RECEIVE_SENDMSG(cd *goipmsg.ClientData, ipmsg *goipmsg.IPMSG) error { sl := append(Messages, cd) Messages = sl cmd := cd.Command if cmd.Get(goipmsg.SENDCHECK) { num := cd.PacketNum err := ipmsg.SendMSG(cd.Addr, strconv.Itoa(num), goipmsg.RECVMSG) return err } return nil }
func RECEIVE_BR_ENTRY(cd *goipmsg.ClientData, ipmsg *goipmsg.IPMSG) error { Users[cd.Key()] = cd ipmsg.SendMSG(cd.Addr, ipmsg.Myinfo(), goipmsg.ANSENTRY) return nil }