gf: github.com/johng-cn/gf/g/net/gudp Index | Files

package gudp

import "github.com/johng-cn/gf/g/net/gudp"

Package gtcp provides UDP server and client implementations.

Index

Package Files

gudp.go gudp_conn.go gudp_func.go gudp_server.go

func NewNetConn Uses

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

创建标准库UDP链接操作对象

func Send Uses

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

(面向短链接)发送数据

func SendRecv Uses

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

(面向短链接)发送数据并等待接收返回数据

type Conn Uses

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

封装的链接对象

func NewConn Uses

func NewConn(raddr string, laddr ...string) (*Conn, error)

创建TCP链接

func NewConnByNetConn Uses

func NewConnByNetConn(udp *net.UDPConn) *Conn

将*net.UDPConn对象转换为*Conn对象

func (*Conn) Close Uses

func (c *Conn) Close() error

func (*Conn) LocalAddr Uses

func (c *Conn) LocalAddr() net.Addr

func (*Conn) Recv Uses

func (c *Conn) Recv(length int, retry ...Retry) ([]byte, error)

接收数据

func (*Conn) RecvWithTimeout Uses

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

带超时时间的数据获取

func (*Conn) RemoteAddr Uses

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

func (*Conn) Send Uses

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

发送数据

func (*Conn) SendRecv Uses

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

发送数据并等待接收返回数据

func (*Conn) SendRecvWithTimeout Uses

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

发送数据并等待接收返回数据(带返回超时等待时间)

func (*Conn) SendWithTimeout Uses

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

带超时时间的数据发送

func (*Conn) SetDeadline Uses

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

func (*Conn) SetRecvBufferWait Uses

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

读取全部缓冲区数据时,读取完毕后的写入等待间隔,如果超过该等待时间后仍无可读数据,那么读取操作返回。 该时间间隔不能设置得太大,会影响Recv读取时长(默认为1毫秒)。

func (*Conn) SetRecvDeadline Uses

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

func (*Conn) SetSendDeadline Uses

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

type Retry Uses

type Retry struct {
    Count    int // 重试次数
    Interval int // 重试间隔(毫秒)
}

type Server Uses

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

tcp server结构体

func GetServer Uses

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

获取/创建一个空配置的UDP Server 单例模式,请保证name的唯一性

func NewServer Uses

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

创建一个tcp server对象,并且可以选择指定一个单例名字

func (*Server) Run Uses

func (s *Server) Run() error

执行监听

func (*Server) SetAddress Uses

func (s *Server) SetAddress(address string)

设置参数 - address

func (*Server) SetHandler Uses

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

设置参数 - handler

Package gudp imports 6 packages (graph). Updated 2019-01-16. Refresh now. Tools for package owners.