| 1 |
//go:build windows |
| 2 |
|
| 3 |
package server4 |
| 4 |
|
| 5 |
import ( |
| 6 |
"fmt" |
| 7 |
"net" |
| 8 |
) |
| 9 |
|
| 10 |
// NewIPv4UDPConn returns an UDPv4 connection bound to the IP and port provider |
| 11 |
func NewIPv4UDPConn(iface string, addr *net.UDPAddr) (*net.UDPConn, error) { |
| 12 |
connection, err := net.ListenPacket("udp4", addr.String()) |
| 13 |
if err != nil { |
| 14 |
return nil, fmt.Errorf("We cannot listen on %s and port %d: %v", addr.IP, addr.Port, err) |
| 15 |
} |
| 16 |
udpConn, ok := connection.(*net.UDPConn) |
| 17 |
if !ok { |
| 18 |
return nil, fmt.Errorf("The connection is not of the proper type") |
| 19 |
} |
| 20 |
return udpConn, nil |
| 21 |
} |