NIUCLOUD是一款SaaS管理后台框架多应用插件+云编译。上千名开发者、服务商正在积极拥抱开发者生态。欢迎开发者们免费入驻。一起助力发展! 广告
[TOC] ## 语法 ### Func ``` func LocalPath() (string, error) func LoopbackInterface() (*net.Interface, error) func MulticastSource(network string, ifi *net.Interface) (net.IP, error) func NewLocalListener(network string) (net.Listener, error) func NewLocalPacketListener(network string) (net.PacketConn, error) func RoutedInterface(network string, flags net.Flags) (*net.Interface, error) func SupportsIPv4() bool func SupportsIPv6() bool func SupportsRawSocket() bool func TestConn(t *testing.T, mp MakePipe) func TestableAddress(network, address string) bool func TestableNetwork(network string) bool ``` ## 实例 ### NewLocalListener ``` // 底层就是 127.0.0.1:0 ,生成一个随机端口 listener, err := nettest.NewLocalListener("tcp") if err != nil { log.Fatal(err) } dial, err := net.Dial("tcp", listener.Addr().String()) dial.Write([]byte(`hello world`)) ```