netx

package module
v0.0.0-...-14be229 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 19, 2018 License: MIT Imports: 5 Imported by: 0

README

Golang net Extension Package

GoDoc

Package netx enables port reuse feature on the network transport and provides transparent network address reflection interface through Session Traversal Utilities for NAT (STUN).

Documentation

Overview

Package netx enables port reuse feature on the network transport and provides transparent network address reflection interface through Session Traversal Utilities for NAT (STUN).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dial

func Dial(network, address string) (net.Conn, error)

Dial connects to the address on the named network with reuse port enabled.

The network must be "tcp", "tcp4", "tcp6", "udp", "udp4", or "udp6".

See func net.Dial for a description of the network and address parameters.

func DialTCP

func DialTCP(network, laddr, raddr string) (*net.TCPConn, error)

DialTCP acts like Dial for TCP networks.

If laddr is empty, a local address is automatically chosen.

func DialTimeout

func DialTimeout(network, address string, timeout time.Duration) (net.Conn, error)

DialTimeout acts like Dial but takes a timeout.

See func Dial and net.DialTimeout for further details.

func DialTimeoutTCP

func DialTimeoutTCP(network, laddr, raddr string, timeout time.Duration) (*net.TCPConn, error)

DialTimeoutTCP acts like DialTCP but takes a timeout.

func DialTimeoutUDP

func DialTimeoutUDP(network, laddr, raddr string, timeout time.Duration) (*net.UDPConn, error)

DialTimeoutUDP acts like DialUDP but takes a timeout.

func DialUDP

func DialUDP(network, laddr, raddr string) (*net.UDPConn, error)

DialUDP acts like Dial for UDP networks.

If laddr is empty, a local address is automatically chosen.

func IsPortReusable

func IsPortReusable() bool

IsPortReusable checks whether port reuse feature is available or not.

func Listen

func Listen(network, address string) (net.Listener, error)

Listen announces on the local network address with reuse port enabled.

The network must be "tcp", "tcp4", or "tcp6".

See func net.Listen for further details.

func ListenPacket

func ListenPacket(network, address string) (net.PacketConn, error)

ListenPacket announces on the local network address with reuse port enabled.

The network must be "udp", "udp4", or "udp6".

See func net.Listen for further details.

func ListenTCP

func ListenTCP(network, address string) (*net.TCPListener, error)

ListenTCP acts like Listen for TCP networks.

func ListenUDP

func ListenUDP(network, address string) (*net.UDPConn, error)

ListenUDP acts like Listen for UDP networks.

func ReusePort

func ReusePort(network, address string, c syscall.RawConn) error

ReusePort used by netx to enable reuse port feature by default. It also can be used on the Control field in net.ListenConfig or net.Dialer to create custom ListenConfig or Dialer with reuse port capability.

lc := net.ListenConfig{Control: netx.ReusePort}
listener, err := lc.Listen("tcp", ":3000")

ReusePort only available on TCP and UDP connection.

Types

type UDPConn

type UDPConn struct {
	// contains filtered or unexported fields
}

UDPConn is the remote bind address reflection interface for net.UDPConn.

func ListenRemoteUDP

func ListenRemoteUDP(network, localAddress, stunAddress string) (*UDPConn, error)

ListenRemoteUDP acts like ListenUDP but with remote bind address reflection.

func (*UDPConn) Close

func (u *UDPConn) Close() error

Close closes the connection.

func (*UDPConn) RemoteAddr

func (u *UDPConn) RemoteAddr() net.Addr

RemoteAddr returns the reflected remote bind address. The Addr returned is shared by all invocations of RemoteAddr, so do not modify it.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL