Documentation ¶
Index ¶
- Constants
- Variables
- type RecvNode
- type ServerNotify
- type UDPClientEx
- type UDPConnection
- func (us *UDPConnection) Close() error
- func (us *UDPConnection) GetAddr() string
- func (uc *UDPConnection) GetLastRecvMillis() int64
- func (us *UDPConnection) GetUserData() any
- func (us *UDPConnection) Init(recver UDPReceiver, notify UDPNotify, parent *UDPServerEx)
- func (uc *UDPConnection) IsTimeoutFor(timeoutmillis int64) bool
- func (us *UDPConnection) Poll() *RecvNode
- func (us *UDPConnection) Recv(data []byte)
- func (us *UDPConnection) Send(code int32, data []byte)
- func (us *UDPConnection) SetUserData(data any)
- type UDPNotify
- type UDPReceiver
- type UDPServerEx
- func (us *UDPServerEx) Close() error
- func (us *UDPServerEx) GetTimoutMillis() int64
- func (us *UDPServerEx) Init(recver UDPReceiver, notify UDPNotify)
- func (us *UDPServerEx) Listen(ipPort string)
- func (us *UDPServerEx) SetServerNotify(servernotify ServerNotify)
- func (us *UDPServerEx) SetTimoutMillis(t int64)
- func (us *UDPServerEx) Work()
Constants ¶
View Source
const ( ACKTYPE_ACK int = 1 ACKTYPE_CONFIRM int = 2 )
View Source
const ( START_SN int64 = 12345 // 起始SN,防止攻击用的。 BASE_SIZE int = 540 // UDP最大包 MAXSMALL int32 = math.MaxInt32 / int32(BASE_SIZE) // 最大多少个分包 // 接受方向发送方回馈一个ACK码,非固定的code值,而是从中随机一个。 CODE_ACK_START int32 = -200 CODE_ACK_END int32 = -75 CODE_CONFIRM_START int32 = -11200 CODE_CONFIRM_END int32 = -10200 SEND_TIMEOUT_MS int64 = 2000 // 发生超时 ms CRC32_FILL uint32 = 89212 TIMEOUT_RETRY_MAX int = 4096 )
View Source
const ( ALIVE_LIVE = 1 ALIVE_STOP = 0 ALIVE_EXIT = -1 )
Variables ¶
View Source
var EMPTY_BYTES = make([]byte, 0)
Functions ¶
This section is empty.
Types ¶
type ServerNotify ¶
type ServerNotify interface { // 链接断开 OnClientDead(conn *UDPConnection) }
*
UDP 通知接口
type UDPClientEx ¶
type UDPClientEx struct {
// contains filtered or unexported fields
}
func (*UDPClientEx) Close ¶
func (uc *UDPClientEx) Close()
func (*UDPClientEx) Init ¶
func (uc *UDPClientEx) Init(ipport string, recver UDPReceiver, notify UDPNotify)
func (*UDPClientEx) Send ¶
func (uc *UDPClientEx) Send(code int32, data []byte)
type UDPConnection ¶
type UDPConnection struct {
// contains filtered or unexported fields
}
TODO: 拆为发送方 和 接收方, 便于代码维护
func NewUDPConnection ¶
func (*UDPConnection) Close ¶
func (us *UDPConnection) Close() error
func (*UDPConnection) GetAddr ¶
func (us *UDPConnection) GetAddr() string
func (*UDPConnection) GetLastRecvMillis ¶
func (uc *UDPConnection) GetLastRecvMillis() int64
func (*UDPConnection) GetUserData ¶
func (us *UDPConnection) GetUserData() any
func (*UDPConnection) Init ¶
func (us *UDPConnection) Init(recver UDPReceiver, notify UDPNotify, parent *UDPServerEx)
func (*UDPConnection) IsTimeoutFor ¶
func (uc *UDPConnection) IsTimeoutFor(timeoutmillis int64) bool
是否已经超时指定的毫秒
func (*UDPConnection) Poll ¶
func (us *UDPConnection) Poll() *RecvNode
func (*UDPConnection) Recv ¶
func (us *UDPConnection) Recv(data []byte)
func (*UDPConnection) Send ¶
func (us *UDPConnection) Send(code int32, data []byte)
func (*UDPConnection) SetUserData ¶
func (us *UDPConnection) SetUserData(data any)
type UDPNotify ¶
type UDPNotify interface { // 发送成功接口 OnSentSuccess(code int32) // 发送空了 OnSentEmpty() }
*
UDP 通知接口
type UDPReceiver ¶
type UDPReceiver interface {
OnRecv(conn *UDPConnection, code int32, data []byte)
}
*
- 接受UDP包的接口
type UDPServerEx ¶
type UDPServerEx struct {
// contains filtered or unexported fields
}
func (*UDPServerEx) Close ¶
func (us *UDPServerEx) Close() error
func (*UDPServerEx) GetTimoutMillis ¶
func (us *UDPServerEx) GetTimoutMillis() int64
func (*UDPServerEx) Init ¶
func (us *UDPServerEx) Init(recver UDPReceiver, notify UDPNotify)
func (*UDPServerEx) Listen ¶
func (us *UDPServerEx) Listen(ipPort string)
func (*UDPServerEx) SetServerNotify ¶
func (us *UDPServerEx) SetServerNotify(servernotify ServerNotify)
func (*UDPServerEx) SetTimoutMillis ¶
func (us *UDPServerEx) SetTimoutMillis(t int64)
func (*UDPServerEx) Work ¶
func (us *UDPServerEx) Work()
Click to show internal directories.
Click to hide internal directories.