Use net.Conn interface instead net.PacketConn for UDP
Share code between TCP and UDP modes