network

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 10, 2023 License: MIT Imports: 16 Imported by: 3

Documentation

Index

Constants

View Source
const (
	PACKET_LEN_BYTE  = 1
	PACKET_LEN_WORD  = 2
	PACKET_LEN_DWORD = 4
)
View Source
const (
	IDLE_TIMEOUT    = iota
	CONNECT_TIMEOUT = iota
	CONNECT_TYPE    = iota
)
View Source
const (
	SSF_NULL = iota
	SSF_RUN  = iota
	SSF_STOP = iota
)
View Source
const (
	CLIENT_CONNECT = iota
	SERVER_CONNECT = iota
)
View Source
const (
	MAX_SEND_CHAN  = 100
	HEART_TIME_OUT = 30
)

Variables

View Source
var (
	DISCONNECTINT = crc32.ChecksumIEEE([]byte("DISCONNECT"))
	HEART_PACKET  = crc32.ChecksumIEEE([]byte("heardpacket"))
)

Functions

This section is empty.

Types

type ClientSocket

type ClientSocket struct {
	Socket
	// contains filtered or unexported fields
}

func (*ClientSocket) Connect

func (c *ClientSocket) Connect() bool

func (*ClientSocket) Init

func (c *ClientSocket) Init(ip string, port int32, params ...OpOption) bool

func (*ClientSocket) OnDisconnect

func (c *ClientSocket) OnDisconnect()

func (*ClientSocket) OnNetFail

func (c *ClientSocket) OnNetFail(int)

func (*ClientSocket) Restart

func (c *ClientSocket) Restart() bool

func (*ClientSocket) Run

func (c *ClientSocket) Run() bool

func (*ClientSocket) Send

func (c *ClientSocket) Send(head rpc.RpcHead, packet rpc.Packet) int

func (*ClientSocket) SendMsg

func (c *ClientSocket) SendMsg(head rpc.RpcHead, funcName string, params ...interface{})

func (*ClientSocket) Start

func (c *ClientSocket) Start() bool

type HandlePacket

type HandlePacket func(buff []byte)

type IClientSocket

type IClientSocket interface {
	ISocket
}

type IServerSocket

type IServerSocket interface {
	ISocket
	AssignClientId() uint32
	GetClientById(uint32) *ServerSocketClient
	LoadClient() *ServerSocketClient
	AddClinet(*net.TCPConn, string, int) *ServerSocketClient
	DelClinet(*ServerSocketClient) bool
	StopClient(uint32)
}

type IServerSocketClient

type IServerSocketClient interface {
	ISocket
}

type ISocket

type ISocket interface {
	Init(string, int, ...OpOption) bool
	Start() bool
	Stop() bool
	Run() bool
	Restart() bool
	Connect() bool
	Disconnect(bool) bool
	OnNetFail(int)
	Clear()
	Close()
	SendMsg(rpc.RpcHead, string, ...interface{})
	Send(rpc.RpcHead, rpc.Packet) int
	CallMsg(rpc.RpcHead, string, ...interface{}) //回调消息处理

	GetId() uint32
	GetState() int32
	SetState(int32)
	SetReceiveBufferSize(int32)
	GetReceiveBufferSize() int32
	SetMaxPacketLen(int32)
	GetMaxPacketLen() int32
	BindPacketFunc(PacketFunc)
	SetConnectType(int32)
	SetConn(net.Conn)
	HandlePacket([]byte)
}

type IWebSocket

type IWebSocket interface {
	ISocket
	AssignClientId() uint32
	GetClientById(uint32) *WebSocketClient
	LoadClient() *WebSocketClient
	AddClinet(*websocket.Conn, string, int) *WebSocketClient
	DelClinet(*WebSocketClient) bool
	StopClient(uint32)
}

type IWebSocketClient

type IWebSocketClient interface {
	ISocket
}

type Op

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

type OpOption

type OpOption func(*Op)

func WithKcp

func WithKcp() OpOption

type PacketConfig

type PacketConfig struct {
	MaxPacketLen *int
	Func         HandlePacket
}

type PacketFunc

type PacketFunc func(packet rpc.Packet) bool

type PacketParser

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

func NewPacketParser

func NewPacketParser(conf PacketConfig) PacketParser

func (*PacketParser) Read

func (p *PacketParser) Read(data []byte) bool

func (*PacketParser) Write

func (p *PacketParser) Write(data []byte) []byte

type ServerSocket

type ServerSocket struct {
	Socket
	// contains filtered or unexported fields
}

func (*ServerSocket) AddClient

func (s *ServerSocket) AddClient(conn net.Conn, addr string, connectType int32) *ServerSocketClient

func (*ServerSocket) AssignClientId

func (s *ServerSocket) AssignClientId() uint32

func (*ServerSocket) Close

func (s *ServerSocket) Close()

func (*ServerSocket) Connect

func (s *ServerSocket) Connect() bool

func (*ServerSocket) DelClient

func (s *ServerSocket) DelClient(client *ServerSocketClient) bool

func (*ServerSocket) Disconnect

func (s *ServerSocket) Disconnect(bool) bool

func (*ServerSocket) GetClientById

func (s *ServerSocket) GetClientById(id uint32) *ServerSocketClient

func (*ServerSocket) Init

func (s *ServerSocket) Init(ip string, port int32, params ...OpOption) bool

func (*ServerSocket) LoadClient

func (s *ServerSocket) LoadClient() *ServerSocketClient

func (*ServerSocket) OnNetFail

func (s *ServerSocket) OnNetFail(int)

func (*ServerSocket) Restart

func (s *ServerSocket) Restart() bool

func (*ServerSocket) Run

func (s *ServerSocket) Run() bool

func (*ServerSocket) RunKcp

func (s *ServerSocket) RunKcp() bool

func (*ServerSocket) Send

func (s *ServerSocket) Send(head rpc.RpcHead, packet rpc.Packet) int

func (*ServerSocket) SendMsg

func (s *ServerSocket) SendMsg(head rpc.RpcHead, funcName string, params ...interface{})

func (*ServerSocket) Start

func (s *ServerSocket) Start() bool

func (*ServerSocket) StopClient

func (s *ServerSocket) StopClient(id uint32)

type ServerSocketClient

type ServerSocketClient struct {
	Socket
	// contains filtered or unexported fields
}

func (*ServerSocketClient) Close

func (s *ServerSocketClient) Close()

func (*ServerSocketClient) DoSend

func (s *ServerSocketClient) DoSend(buff []byte) int

func (*ServerSocketClient) Init

func (s *ServerSocketClient) Init(ip string, port int32, params ...OpOption) bool

func (*ServerSocketClient) OnNetFail

func (s *ServerSocketClient) OnNetFail(error int)

func (*ServerSocketClient) Run

func (s *ServerSocketClient) Run() bool

func (*ServerSocketClient) Send

func (s *ServerSocketClient) Send(head rpc.RpcHead, packet rpc.Packet) int

func (*ServerSocketClient) SendLoop

func (s *ServerSocketClient) SendLoop() bool

func (*ServerSocketClient) Start

func (s *ServerSocketClient) Start() bool

func (*ServerSocketClient) Stop

func (s *ServerSocketClient) Stop() bool

func (*ServerSocketClient) Update

func (s *ServerSocketClient) Update()

type Socket

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

func (*Socket) BindPacketFunc

func (this *Socket) BindPacketFunc(callfunc PacketFunc)

func (*Socket) CallMsg

func (this *Socket) CallMsg(head rpc.RpcHead, funcName string, params ...interface{})

func (*Socket) Clear

func (this *Socket) Clear()

func (*Socket) Close

func (this *Socket) Close()

func (*Socket) Connect

func (this *Socket) Connect() bool

func (*Socket) Disconnect

func (this *Socket) Disconnect(bool) bool

func (*Socket) GetId

func (this *Socket) GetId() uint32

func (*Socket) GetMaxPacketLen

func (this *Socket) GetMaxPacketLen() int32

func (*Socket) GetReceiveBufferSize

func (this *Socket) GetReceiveBufferSize() int32

func (*Socket) GetState

func (this *Socket) GetState() int32

func (*Socket) HandlePacket

func (this *Socket) HandlePacket(buff []byte)

func (*Socket) Init

func (this *Socket) Init(ip string, port int32, params ...OpOption) bool

func (*Socket) OnNetFail

func (this *Socket) OnNetFail(int)

func (*Socket) Restart

func (this *Socket) Restart() bool

func (*Socket) Run

func (this *Socket) Run() bool

func (*Socket) Send

func (this *Socket) Send(rpc.RpcHead, rpc.Packet) int

func (*Socket) SendMsg

func (this *Socket) SendMsg(head rpc.RpcHead, funcName string, params ...interface{})

func (*Socket) SetConn

func (this *Socket) SetConn(conn net.Conn)

func (*Socket) SetConnectType

func (this *Socket) SetConnectType(connType int32)

func (*Socket) SetMaxPacketLen

func (this *Socket) SetMaxPacketLen(maxReceiveSize int32)

func (*Socket) SetReceiveBufferSize

func (this *Socket) SetReceiveBufferSize(maxSendSize int32)

func (*Socket) SetState

func (this *Socket) SetState(state int32)

func (*Socket) Start

func (this *Socket) Start() bool

func (*Socket) Stop

func (this *Socket) Stop() bool

type WebSocket

type WebSocket struct {
	Socket
	// contains filtered or unexported fields
}

func (*WebSocket) AddClient

func (w *WebSocket) AddClient(tcpConn *websocket.Conn, addr string, connectType int32) *WebSocketClient

func (*WebSocket) AssignClientId

func (w *WebSocket) AssignClientId() uint32

func (*WebSocket) Close

func (w *WebSocket) Close()

func (*WebSocket) Connect

func (w *WebSocket) Connect() bool

func (*WebSocket) DelClient

func (w *WebSocket) DelClient(client *WebSocketClient) bool

func (*WebSocket) Disconnect

func (w *WebSocket) Disconnect(bool) bool

func (*WebSocket) GetClientById

func (w *WebSocket) GetClientById(id uint32) *WebSocketClient

func (*WebSocket) Init

func (w *WebSocket) Init(ip string, port int32, params ...OpOption) bool

func (*WebSocket) LoadClient

func (w *WebSocket) LoadClient() *WebSocketClient

func (*WebSocket) OnNetFail

func (w *WebSocket) OnNetFail(int)

func (*WebSocket) Restart

func (w *WebSocket) Restart() bool

func (*WebSocket) Send

func (w *WebSocket) Send(head rpc.RpcHead, packet rpc.Packet) int

func (*WebSocket) SendMsg

func (w *WebSocket) SendMsg(head rpc.RpcHead, funcName string, params ...interface{})

func (*WebSocket) Start

func (w *WebSocket) Start() bool

func (*WebSocket) StopClient

func (w *WebSocket) StopClient(id uint32)

type WebSocketClient

type WebSocketClient struct {
	Socket
	// contains filtered or unexported fields
}

func (*WebSocketClient) Close

func (w *WebSocketClient) Close()

func (*WebSocketClient) DoSend

func (w *WebSocketClient) DoSend(buff []byte) int

func (*WebSocketClient) Init

func (w *WebSocketClient) Init(ip string, port int32, params ...OpOption) bool

func (*WebSocketClient) OnNetFail

func (w *WebSocketClient) OnNetFail(error int)

func (*WebSocketClient) Run

func (w *WebSocketClient) Run() bool

func (*WebSocketClient) Send

func (w *WebSocketClient) Send(head rpc.RpcHead, packet rpc.Packet) int

func (*WebSocketClient) SendLoop

func (w *WebSocketClient) SendLoop() bool

func (*WebSocketClient) Start

func (w *WebSocketClient) Start() bool

func (*WebSocketClient) Stop

func (w *WebSocketClient) Stop() bool

func (*WebSocketClient) Update

func (w *WebSocketClient) Update() bool

Jump to

Keyboard shortcuts

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