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 }
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()) }
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) } }