Documentation
¶
Index ¶
- Constants
- func StartTcpSvr(address string, instance InterfaceNet)
- func StartWebSocket(addr string, instance InterfaceNet)
- type Connection
- func NewNetClient(bindAddress string, iConn InterfaceNet, timeoutMillisecond int, ...) *Connection
- func NewTcpClientConnect(bindAddress string, iConn InterfaceNet, timeoutMillisecond int, ...) *Connection
- func NewTcpConnection(conn net.Conn, iconn InterfaceNet) *Connection
- func NewWebSockConnection(conn *websocket.Conn, iconn InterfaceNet) *Connection
- func NewWebsockClientConnect(bindAddress string, iConn InterfaceNet, timeoutMillisecond int, ...) *Connection
- func (c *Connection) CbExist(cmd PackHeadCmd) bool
- func (c *Connection) CbGetFunc(cmd PackHeadCmd) reflect.Value
- func (c *Connection) CbGetProto(cmd PackHeadCmd) reflect.Type
- func (c *Connection) CbMessageRouter(cmd PackHeadCmd, cb interface{}, msg interface{})
- func (c *Connection) CloseConnWithoutRecon(err error)
- func (c *Connection) PrintNetProtocol()
- func (c *Connection) WriteBytes(bin []byte, cmd uint32) (n int, err error)
- func (c *Connection) WriteMessage(msg *PackHead) (n int, err error)
- func (c *Connection) WriteMessageWaitResponseWithinTimeLimit(msg *PackHead, timeLimitMillisecond int64) (ackMsg *PackHead, isTimeOut bool)
- func (c *Connection) WriteMessageWithCallback(msg *PackHead, cb DefNetIOCallback) (n int, err error)
- func (c *Connection) WriteSeqBytes(bin []byte, cmd uint32, seq uint32) (n int, err error)
- type DefNetIOCallback
- type InterfaceNet
- type InterfaceServer
- type NetProtocolType
- type PackHead
- type PackHeadCmd
- type PackHeadReserveHigh
- type PackHeadReserveLow
- type PackHeadSequenceId
Constants ¶
View Source
const ( ConnectionStateConnected = 1 ConnectionStateClosed = 2 )
View Source
const ( ProtoTcp = "tcp://" ProtoWebSock = "ws://" )
Variables ¶
This section is empty.
Functions ¶
func StartTcpSvr ¶
func StartTcpSvr(address string, instance InterfaceNet)
func StartWebSocket ¶
func StartWebSocket(addr string, instance InterfaceNet)
Types ¶
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
抛出的连接对象
func NewNetClient ¶
func NewNetClient(bindAddress string, iConn InterfaceNet, timeoutMillisecond int, endlessReconnect bool) *Connection
func NewTcpClientConnect ¶
func NewTcpClientConnect(bindAddress string, iConn InterfaceNet, timeoutMillisecond int, endlessReconnect bool) *Connection
func NewTcpConnection ¶
func NewTcpConnection(conn net.Conn, iconn InterfaceNet) *Connection
func NewWebSockConnection ¶
func NewWebSockConnection(conn *websocket.Conn, iconn InterfaceNet) *Connection
func NewWebsockClientConnect ¶
func NewWebsockClientConnect(bindAddress string, iConn InterfaceNet, timeoutMillisecond int, endlessReconnect bool) *Connection
func (*Connection) CbExist ¶
func (c *Connection) CbExist(cmd PackHeadCmd) bool
func (*Connection) CbGetFunc ¶
func (c *Connection) CbGetFunc(cmd PackHeadCmd) reflect.Value
func (*Connection) CbGetProto ¶
func (c *Connection) CbGetProto(cmd PackHeadCmd) reflect.Type
func (*Connection) CbMessageRouter ¶
func (c *Connection) CbMessageRouter(cmd PackHeadCmd, cb interface{}, msg interface{})
cmd 消息id f 处理消息的函数 如: login(session *server.ClientSession, req *protocol.CLogin) (resp proto.Message, err error) msg 消息对应的protobuf请求包类型
func (*Connection) CloseConnWithoutRecon ¶
func (c *Connection) CloseConnWithoutRecon(err error)
func (*Connection) PrintNetProtocol ¶
func (c *Connection) PrintNetProtocol()
func (*Connection) WriteBytes ¶
func (c *Connection) WriteBytes(bin []byte, cmd uint32) (n int, err error)
func (*Connection) WriteMessage ¶
func (c *Connection) WriteMessage(msg *PackHead) (n int, err error)
func (*Connection) WriteMessageWaitResponseWithinTimeLimit ¶
func (c *Connection) WriteMessageWaitResponseWithinTimeLimit(msg *PackHead, timeLimitMillisecond int64) (ackMsg *PackHead, isTimeOut bool)
* client allowed only method. server connection should not call it.
func (*Connection) WriteMessageWithCallback ¶
func (c *Connection) WriteMessageWithCallback(msg *PackHead, cb DefNetIOCallback) (n int, err error)
* client allowed only method. server connection should not call it.
func (*Connection) WriteSeqBytes ¶
type DefNetIOCallback ¶
type DefNetIOCallback = func(msg *PackHead)
type InterfaceNet ¶
type InterfaceNet interface { IOnInit(*Connection) //初始化操作,比如心跳的设置... IOnProcessPack(*PackHead) //处理消息 /* * this interface SHOULD NOT CALL close. */ IOnClose(err error) (tryReconnect bool) // IOnConnect(isOk bool) IOnNewConnection(connection *Connection) }
type InterfaceServer ¶
type InterfaceServer interface { }
type NetProtocolType ¶
type NetProtocolType uint32
const ( NetProtocolTypeTCP NetProtocolType = 1 NetProtocolTypeWebSock NetProtocolType = 2 NetProtocolTypeUndefined NetProtocolType = 2 )
func ParseNetIpFromAddressWithProtocol ¶
func ParseNetIpFromAddressWithProtocol(address string) (_addr string, protocolType NetProtocolType)
type PackHead ¶
type PackHead struct { /* * [4,8) * cmd enum, 命令字枚举 */ Cmd uint32 /* * [8,12) * 客户端自增,原样返回给客户端(如果服务器使用websocket) */ SequenceID uint32 /* * [12, 16),鉴于websocket本身是应用层协议,已经处理了包的概念,忽略此字段 */ Length uint32 /* * [16,20) 高位保留字段 * mq中,High 字段用来存储消息发布的status,0表示成功,1表示超时 */ ReserveHigh uint32 /* * [20,24) 低位保留字段, mq中存储mq的业务模型。 */ ReserveLow uint32 /* * [24, 24+length ) */ Body []byte // contains filtered or unexported fields }
* websocket版私有协议体定义 *
func (*PackHead) SerializePackHead ¶
type PackHeadCmd ¶
type PackHeadCmd = uint32
type PackHeadReserveHigh ¶
type PackHeadReserveHigh = uint32
type PackHeadReserveLow ¶
type PackHeadReserveLow = uint32
type PackHeadSequenceId ¶
type PackHeadSequenceId = uint32
Click to show internal directories.
Click to hide internal directories.