Documentation
¶
Index ¶
- Constants
- func GetFreePort() (port int, err error)
- func GetFreePorts(count int) (ports []int, err error)
- func MustGetFreePort() (port int)
- func NewNetConn(remoteAddress string, localAddress ...string) (*net.UDPConn, error)
- func Send(address string, data []byte, retry ...Retry) error
- func SendReceive(address string, data []byte, receive int, retry ...Retry) ([]byte, error)
- type Conn
- func (c *Conn) Receive(length int, retry ...Retry) ([]byte, error)
- func (c *Conn) ReceiveWithTimeout(length int, timeout time.Duration, retry ...Retry) (data []byte, err error)
- func (c *Conn) RemoteAddr() net.Addr
- func (c *Conn) Send(data []byte, retry ...Retry) (err error)
- func (c *Conn) SendReceive(data []byte, receive int, retry ...Retry) ([]byte, error)
- func (c *Conn) SendReceiveWithTimeout(data []byte, receive int, timeout time.Duration, retry ...Retry) ([]byte, error)
- func (c *Conn) SendWithTimeout(data []byte, timeout time.Duration, retry ...Retry) (err error)
- func (c *Conn) SetDeadline(t time.Time) (err error)
- func (c *Conn) SetReceiveBufferWait(d time.Duration)
- func (c *Conn) SetReceiveDeadline(t time.Time) (err error)
- func (c *Conn) SetSendDeadline(t time.Time) (err error)
- type Retry
- type Server
Constants ¶
View Source
const (
// FreePortAddress 使用随机端口标记服务器监听。
FreePortAddress = ":0"
)
Variables ¶
This section is empty.
Functions ¶
func GetFreePorts ¶
GetFreePorts 检索并返回指定数量的空闲端口。
func MustGetFreePort ¶
func MustGetFreePort() (port int)
MustGetFreePort 执行 GetFreePort,但发生任何错误都会 panic。
func NewNetConn ¶
NewNetConn 创建并返回具有指定地址的 *net.UDPConn。
Types ¶
type Conn ¶
Conn 处理 UDP 连接。
func NewConnByNetConn ¶
NewConnByNetConn 使用指定的 *net.UDPConn 对象创建一个 UDP 连接对象。
func (*Conn) ReceiveWithTimeout ¶
func (c *Conn) ReceiveWithTimeout(length int, timeout time.Duration, retry ...Retry) (data []byte, err error)
ReceiveWithTimeout 从远程地址读取数据超时。
func (*Conn) RemoteAddr ¶
RemoteAddr 返回当前 UDP 连接的远程地址。 请注意,它不能使用 c.conn.RemoteAddr(),因为它是 nil。
func (*Conn) SendReceive ¶
SendReceive 将数据写入连接并阻止读取响应。
func (*Conn) SendReceiveWithTimeout ¶
func (c *Conn) SendReceiveWithTimeout(data []byte, receive int, timeout time.Duration, retry ...Retry) ([]byte, error)
SendReceiveWithTimeout 将数据写入连接并读取超时响应。
func (*Conn) SendWithTimeout ¶
SendWithTimeout 将数据写入超时连接。
func (*Conn) SetReceiveBufferWait ¶
SetReceiveBufferWait 从连接读取所有数据时设置缓冲区等待超时。 等待时间不能太长,否则可能会延迟从远程地址接收数据。
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server 定义 UDP 服务器。
func (*Server) GetListenedAddress ¶
GetListenedAddress 获取当前服务器监听地址。
func (*Server) GetListenedPort ¶
GetListenedPort 获取当前服务器监听端口。
Click to show internal directories.
Click to hide internal directories.