func handleClient(conn *net.IPConn) { var buf [512]byte n, addr, err := conn.ReadFromIP(buf[0:]) if err != nil { return } fmt.Println("Receive from client", addr.string(), string(buf[0:n])) conn.WriteToIP([]byte("Welcome Client!"), addr) }
func listen(conn *net.IPConn) { buf := make([]byte, 9999) for { n, _, err := conn.ReadFromIP(buf) if err != nil { log.Panic(err) } s := string(buf[:n]) log.Printf("RECV %s", s) f := strings.Fields(s) if len(f) == 0 { log.Print("skipping zero-field message") continue } for _, c := range receivers { c <- Msg{f} } } }