gudp

package
v1.4.7 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2019 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package gtcp provides UDP server and client implementations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewNetConn

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

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

func Send

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

(面向短链接)发送数据

func SendRecv

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

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

Types

type Conn

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

封装的链接对象

func NewConn

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

创建TCP链接

func NewConnByNetConn

func NewConnByNetConn(udp *net.UDPConn) *Conn

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

func (*Conn) Close

func (c *Conn) Close() error

func (*Conn) LocalAddr

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

func (*Conn) Recv

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

接收数据

func (*Conn) RecvWithTimeout

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

带超时时间的数据获取

func (*Conn) RemoteAddr

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

func (*Conn) Send

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

发送数据

func (*Conn) SendRecv

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

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

func (*Conn) SendRecvWithTimeout

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

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

func (*Conn) SendWithTimeout

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

带超时时间的数据发送

func (*Conn) SetDeadline

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

func (*Conn) SetRecvBufferWait

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

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

func (*Conn) SetRecvDeadline

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

func (*Conn) SetSendDeadline

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

type Retry

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

type Server

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

tcp server结构体

func GetServer

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

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

func NewServer

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

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

func (*Server) Run

func (s *Server) Run() error

执行监听

func (*Server) SetAddress

func (s *Server) SetAddress(address string)

设置参数 - address

func (*Server) SetHandler

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

设置参数 - handler

Jump to

Keyboard shortcuts

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