Exemple #1
0
func newSwimmer(s *Swim) (ret *swimmer, err error) {
	ret = &swimmer{s: s}
	cliAddr := net.UDPAddr{IP: s.Addr.IP, Port: 0}
	ret.clientConn, err = net.ListenUDP(cliAddr.Network(), &cliAddr)
	if err != nil {
		glog.Errorf("Swim: Unable to listen on client udp %s: %s", &cliAddr, err)
		return nil, err
	}
	glog.V(2).Infof("Client on %s", ret.clientConn.LocalAddr())
	return
}
Exemple #2
0
func main() {
	//exit := make(chan bool)
	ip := net.ParseIP("127.0.0.1")
	port := 81
	tcp_addr := net.TCPAddr{ip, port, ""}
	udp_addr := net.UDPAddr{ip, port, ""}
	fmt.Println(tcp_addr)
	fmt.Println(udp_addr)
	fmt.Println(tcp_addr.Network())
	fmt.Println(udp_addr.Network())
}
Exemple #3
0
func write(addr *net.UDPAddr, i int) {
	log.Printf("Start `write` test with %d iteration\n", i)

	conn, err := net.DialUDP(addr.Network(), nil, addr)
	chk(err)

	payload := make([]byte, payload_sz)
	for ; i > 0; i-- {
		_, err := conn.Write(payload)
		chk(err)
	}
}