tcp

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: May 30, 2021 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PingInterval = time.Second * 3
)
View Source
const (
	TimeOut = time.Second * 15
)

Variables

This section is empty.

Functions

func Dial

func Dial(addr string, ctx *lokas.Context) (*conn.Conn, error)

func DialEx

func DialEx(addr string, ctx *lokas.Context, retryWait time.Duration) chan struct{}

Types

type ClientSession

type ClientSession struct {
	util.ID

	Messages chan []byte
	Conn     lokas.IConn
	Protocol protocol.TYPE

	OnCloseFunc func(conn lokas.IConn)
	OnOpenFunc  func(conn lokas.IConn)
	MsgHandler  func(msg *protocol.BinaryMessage)
	// contains filtered or unexported fields
}

func NewClientSession

func NewClientSession(conn lokas.IConn, id util.ID, manager lokas.ISessionManager, opts ...SessionOption) *ClientSession

func (*ClientSession) AsyncCall

func (this *ClientSession) AsyncCall(actorId util.ID, transId uint32, req protocol.ISerializable, resp protocol.ISerializable) error

func (*ClientSession) Call

func (this *ClientSession) Call(actorId util.ID, transId uint32, req protocol.ISerializable, resp protocol.ISerializable) error

func (*ClientSession) CloneEntity

func (this *ClientSession) CloneEntity() *ecs.Entity

func (*ClientSession) GetConn

func (this *ClientSession) GetConn() lokas.IConn

func (*ClientSession) GetId

func (this *ClientSession) GetId() util.ID

func (*ClientSession) GetProcess

func (this *ClientSession) GetProcess() lokas.IProcess

func (*ClientSession) HandleMessage

func (this *ClientSession) HandleMessage(f func(msg *protocol.BinaryMessage))

func (*ClientSession) OnClose

func (this *ClientSession) OnClose(conn lokas.IConn)

func (*ClientSession) OnCreate

func (this *ClientSession) OnCreate() error

func (*ClientSession) OnDestroy

func (this *ClientSession) OnDestroy() error

func (*ClientSession) OnMessage

func (this *ClientSession) OnMessage(actorId util.ID, transId uint32, msg protocol.ISerializable) error

func (*ClientSession) OnOpen

func (this *ClientSession) OnOpen(conn lokas.IConn)

func (*ClientSession) OnRecv

func (this *ClientSession) OnRecv(conn lokas.IConn, data []byte)

func (*ClientSession) PongHandler

func (this *ClientSession) PongHandler(pong *protocol.Pong)

func (*ClientSession) SendMessage

func (this *ClientSession) SendMessage(actorId util.ID, transId uint32, msg protocol.ISerializable) error

func (*ClientSession) SetId

func (this *ClientSession) SetId(id util.ID)

func (*ClientSession) SetProcess

func (this *ClientSession) SetProcess(process lokas.IProcess)

func (*ClientSession) Start

func (this *ClientSession) Start() error

func (*ClientSession) Stop

func (this *ClientSession) Stop() error

func (*ClientSession) Type

func (this *ClientSession) Type() string

func (*ClientSession) Update

func (this *ClientSession) Update(dt time.Duration, now time.Time)

func (*ClientSession) Write

func (this *ClientSession) Write(data []byte) error

type Server

type Server struct {
	Context *lokas.Context
	// contains filtered or unexported fields
}

func NewServer

func NewServer(context *lokas.Context) *Server

NewServer create a new tcp server

func (*Server) Broadcast

func (this *Server) Broadcast(sessionIds []util.ID, data []byte)

Broadcast broadcast data to all active connections

func (*Server) GetActiveConnNum

func (this *Server) GetActiveConnNum() int

GetActiveConnNum get count of active connections

func (*Server) Start

func (this *Server) Start(addr string) error

Start start tcp server

func (*Server) Stop

func (this *Server) Stop()

Stop stop tcp server

type SessionOption

type SessionOption func(*ClientSession)

func WithCloseFunc

func WithCloseFunc(closeFunc func(conn lokas.IConn)) SessionOption

func WithMsgHandler

func WithMsgHandler(msgHandler func(msg *protocol.BinaryMessage)) SessionOption

func WithOpenFunc

func WithOpenFunc(closeFunc func(conn lokas.IConn)) SessionOption

func WithProtocol

func WithProtocol(protocol protocol.TYPE) SessionOption

type TcpClient

type TcpClient struct {
	events.EventEmmiter
	*ClientSession

	Closing  bool
	Opening  bool
	Protocol protocol.TYPE
	// contains filtered or unexported fields
}

func NewTcpClient

func NewTcpClient(opts ...SessionOption) *TcpClient

func (*TcpClient) Call

func (this *TcpClient) Call(transId uint32, req interface{}) (interface{}, error)

func (*TcpClient) ClearContext

func (this *TcpClient) ClearContext(err error)

func (*TcpClient) Connect

func (this *TcpClient) Connect(addr string) *promise.Promise

func (*TcpClient) Connected

func (this *TcpClient) Connected() bool

func (*TcpClient) Disconnect

func (this *TcpClient) Disconnect(b bool) *promise.Promise

func (*TcpClient) MessageHandler

func (this *TcpClient) MessageHandler(msg *protocol.BinaryMessage)

func (*TcpClient) Off

func (this *TcpClient) Off(cmdId uint16, listener events.Listener)

func (*TcpClient) OnClose

func (this *TcpClient) OnClose(conn lokas.IConn)

func (*TcpClient) OnMessage

func (this *TcpClient) OnMessage(cmdId protocol.BINARY_TAG, listeners ...events.Listener)

func (*TcpClient) OnOpen

func (this *TcpClient) OnOpen(conn lokas.IConn)

func (*TcpClient) OnRecvCmd

func (this *TcpClient) OnRecvCmd(cmdId protocol.BINARY_TAG, time time.Duration) *promise.Promise

func (*TcpClient) Request

func (this *TcpClient) Request(req interface{}, resp interface{}) *promise.Promise

func (*TcpClient) SendMessage

func (this *TcpClient) SendMessage(transId uint32, msg interface{})

Jump to

Keyboard shortcuts

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