Documentation ¶
Index ¶
- Variables
- type AsyncTCPServer
- func (srv *AsyncTCPServer) Close()
- func (srv *AsyncTCPServer) Connect(ip string, callback CallBack, protocol Protocol) (*TCPConn, error)
- func (srv *AsyncTCPServer) GetAllTCPConn() []*TCPConn
- func (srv *AsyncTCPServer) GetTCPConn(key string) *TCPConn
- func (srv *AsyncTCPServer) ListenAndServe() error
- func (srv *AsyncTCPServer) Serve(l *net.TCPListener) error
- func (srv *AsyncTCPServer) SetReadDeadline(t time.Duration)
- func (srv *AsyncTCPServer) SetWriteDeadline(t time.Duration)
- type CallBack
- type DefaultPacket
- type DefaultProtocol
- type Packet
- type PacketType
- type Protocol
- type TCPConn
- func (c *TCPConn) AsyncWritePacket(p Packet) error
- func (c *TCPConn) AsyncWritePacketWithTimeout(p Packet, sec int) error
- func (c *TCPConn) Close()
- func (c *TCPConn) GetExtraData(key string) interface{}
- func (c *TCPConn) GetLocalAddr() net.Addr
- func (c *TCPConn) GetLocalIPAddress() string
- func (c *TCPConn) GetRawConn() *net.TCPConn
- func (c *TCPConn) GetRemoteAddr() net.Addr
- func (c *TCPConn) GetRemoteIPAddress() string
- func (c *TCPConn) IsClosed() bool
- func (c *TCPConn) ReadPacket() (Packet, error)
- func (c *TCPConn) Serve() error
- func (c *TCPConn) SetExtraData(key string, data interface{})
- type TCPConnBucket
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type AsyncTCPServer ¶
type AsyncTCPServer struct {
// contains filtered or unexported fields
}
AsyncTCPServer 结构定义
func NewAsyncTCPServer ¶
func NewAsyncTCPServer(tcpAddr string, callback CallBack, protocol Protocol) *AsyncTCPServer
NewAsyncTCPServer 返回一个AsyncTCPServer实例
func (*AsyncTCPServer) Connect ¶
func (srv *AsyncTCPServer) Connect(ip string, callback CallBack, protocol Protocol) (*TCPConn, error)
Connect 使用指定的callback和protocol连接其他TCPServer,返回TCPConn
func (*AsyncTCPServer) GetAllTCPConn ¶
func (srv *AsyncTCPServer) GetAllTCPConn() []*TCPConn
func (*AsyncTCPServer) GetTCPConn ¶
func (srv *AsyncTCPServer) GetTCPConn(key string) *TCPConn
func (*AsyncTCPServer) ListenAndServe ¶
func (srv *AsyncTCPServer) ListenAndServe() error
ListenAndServe 使用AsyncTCPServer的tcpAddr创建TCPListner并调用Server()方法开启监听
func (*AsyncTCPServer) Serve ¶
func (srv *AsyncTCPServer) Serve(l *net.TCPListener) error
Serve 使用指定的TCPListener开启监听
func (*AsyncTCPServer) SetReadDeadline ¶
func (srv *AsyncTCPServer) SetReadDeadline(t time.Duration)
func (*AsyncTCPServer) SetWriteDeadline ¶
func (srv *AsyncTCPServer) SetWriteDeadline(t time.Duration)
type CallBack ¶
type CallBack interface { //链接建立回调 OnConnected(conn *TCPConn) //消息处理回调 OnMessage(conn *TCPConn, p Packet) //链接断开回调 OnDisconnected(conn *TCPConn) //错误回调 OnError(err error) }
CallBack 是一个回调接口,用于连接的各种事件处理
type DefaultPacket ¶
type DefaultPacket struct { Type PacketType Body []byte }
func NewDefaultPacket ¶
func NewDefaultPacket(t PacketType, body []byte) *DefaultPacket
func (*DefaultPacket) Bytes ¶
func (m *DefaultPacket) Bytes() []byte
type DefaultProtocol ¶
type DefaultProtocol struct {
// contains filtered or unexported fields
}
func (*DefaultProtocol) ReadPacket ¶
func (p *DefaultProtocol) ReadPacket(reader io.Reader) (Packet, error)
func (*DefaultProtocol) ReadPacketLimit ¶
func (*DefaultProtocol) SetMaxPacketSize ¶
func (p *DefaultProtocol) SetMaxPacketSize(n uint32)
func (*DefaultProtocol) WritePacket ¶
func (*DefaultProtocol) WritePacket(writer io.Writer, p Packet) error
type PacketType ¶
type PacketType byte
type TCPConn ¶
type TCPConn struct {
// contains filtered or unexported fields
}
func (*TCPConn) AsyncWritePacket ¶
func (*TCPConn) AsyncWritePacketWithTimeout ¶
func (*TCPConn) GetExtraData ¶
func (*TCPConn) GetLocalAddr ¶
func (*TCPConn) GetLocalIPAddress ¶
LocalIPAddress 返回socket连接本地的ip地址
func (*TCPConn) GetRawConn ¶
func (*TCPConn) GetRemoteAddr ¶
func (*TCPConn) GetRemoteIPAddress ¶
func (*TCPConn) ReadPacket ¶
func (*TCPConn) SetExtraData ¶
type TCPConnBucket ¶
type TCPConnBucket struct {
// contains filtered or unexported fields
}
TCPConnBucket 用来存放和管理TCPConn连接
func NewTCPConnBucket ¶
func NewTCPConnBucket() *TCPConnBucket
func (*TCPConnBucket) Delete ¶
func (b *TCPConnBucket) Delete(id string)
func (*TCPConnBucket) Get ¶
func (b *TCPConnBucket) Get(id string) *TCPConn
func (*TCPConnBucket) GetAll ¶
func (b *TCPConnBucket) GetAll() map[string]*TCPConn
func (*TCPConnBucket) Put ¶
func (b *TCPConnBucket) Put(id string, c *TCPConn)
Source Files ¶
Click to show internal directories.
Click to hide internal directories.