dudp

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewNetConn

func NewNetConn(remoteAddress string, localAddress ...string) (*net.UDPConn, error)

NewNetConn 创建一个udp链接 远端的地址端口,必传 本地使用的地址端口,可选

func Send

func Send(address string, data []byte, retry ...Retry) error

Send 对远端的一个地址端口,发送udp包 address: 远端地址 data : 要发送的数据 retry : 重试配置

func SendRecv

func SendRecv(address string, data []byte, receive int, retry ...Retry) ([]byte, error)

SendRecv 对远端的一个地址端口,发送udp包,并等待接收 address: 远端地址 data : 要发送的数据 receive : 要接收的字节数 retry : 重试配置

Types

type Conn

type Conn struct {
	*net.UDPConn // 底层 UDP 链接.
	// contains filtered or unexported fields
}

Conn udp链接处理对象

func NewConn

func NewConn(remoteAddress string, localAddress ...string) (*Conn, error)

NewConn 创建一个UDP链接,remoteAddress必须传入。localAddress可选

func NewConnByNetConn

func NewConnByNetConn(udp *net.UDPConn) *Conn

NewConnByNetConn 传入底层的udp链接,包装出我们自定义的udp链接

func (*Conn) Recv

func (that *Conn) Recv(bufferSize int, retry ...Retry) ([]byte, error)

Recv 读取指定字节的数据

func (*Conn) RecvWithTimeout

func (that *Conn) RecvWithTimeout(length int, timeout time.Duration, retry ...Retry) (data []byte, err error)

RecvWithTimeout 读取数据,如果指定时间内未读取到数据,则报错返回

func (*Conn) RemoteAddr

func (that *Conn) RemoteAddr() net.Addr

RemoteAddr 获取远端地址

func (*Conn) Send

func (that *Conn) Send(data []byte, retry ...Retry) (err error)

Send 发送数据

func (*Conn) SendRecv

func (that *Conn) SendRecv(data []byte, receive int, retry ...Retry) ([]byte, error)

SendRecv 发送数据到远端,并等待接收远端数据

func (*Conn) SendRecvWithTimeout

func (that *Conn) SendRecvWithTimeout(data []byte, receive int, timeout time.Duration, retry ...Retry) ([]byte, error)

SendRecvWithTimeout 发送数据,并阻塞等待读取数据,在指定的时间内为读取成功,则报错返回

func (*Conn) SendWithTimeout

func (that *Conn) SendWithTimeout(data []byte, timeout time.Duration, retry ...Retry) (err error)

SendWithTimeout 发送数据,在指定的时间内如果还为发送完毕,则报错返回

func (*Conn) SetDeadline

func (that *Conn) SetDeadline(t time.Time) error

SetDeadline 设置链接的读写超时时间

func (*Conn) SetRecvBufferWait

func (that *Conn) SetRecvBufferWait(d time.Duration)

SetRecvBufferWait 设置从连接读取所有数据时的缓冲区等待超时。 等待时间不能太长,否则可能会延迟从远程地址接收数据。

func (*Conn) SetRecvDeadline

func (that *Conn) SetRecvDeadline(t time.Time) error

SetRecvDeadline 单独设置链接的读超时时间

func (*Conn) SetSendDeadline

func (that *Conn) SetSendDeadline(t time.Time) error

SetSendDeadline 单独设置链接的写超时时间

type Retry

type Retry struct {
	Count    int           // 最大重试次数
	Interval time.Duration // 重试间隔.
}

type Server

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

Server UDP server

func GetServer

func GetServer(name ...interface{}) *Server

GetServer 获取一个UDP服务器对象

func NewServer

func NewServer(address string, handler func(*Conn), name ...string) *Server

NewServer 创建一个UDP服务器对象

func (*Server) Close

func (that *Server) Close() error

Close 关闭该UDP服务

func (*Server) Run

func (that *Server) Run() error

Run 启动该UDP服务器

func (*Server) SetAddress

func (that *Server) SetAddress(address string)

SetAddress 设置要监听的本地地址

func (*Server) SetHandler

func (that *Server) SetHandler(handler func(*Conn))

SetHandler 设置收到包后的处理函数

Jump to

Keyboard shortcuts

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