示例#1
0
文件: 14.go 项目: jianyongchen/GoUnix
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)
}
示例#2
0
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}
		}
	}
}