network

package
v1.9.9 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2023 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

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  = 256
	HEART_TIME_OUT = 60
)
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
)

Variables

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

Functions

This section is empty.

Types

type ClientClose

type ClientClose func(id uint32) error

type ClientSocket

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

func (*ClientSocket) Connect

func (c *ClientSocket) Connect() bool

func (*ClientSocket) DoSend

func (this *ClientSocket) DoSend(buff []byte) int

func (*ClientSocket) Init

func (c *ClientSocket) Init(ip string, port int, 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) SendPacket

func (this *ClientSocket) SendPacket(head rpc.RpcHead, funcName string, msg proto.Message) int

func (*ClientSocket) Start

func (c *ClientSocket) Start() bool

type HandlePacket

type HandlePacket func(buff []byte)

type IClientSocket

type IClientSocket interface {
	ISocket
}

type IPacketParser added in v1.6.7

type IPacketParser interface {
	Read(dat []byte) bool
	Write(dat []byte) []byte
	GetMaxPacketLen() int
	SetMaxPacketLen(val int)
	// contains filtered or unexported methods
}

-------------- | len | data | --------------

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(int)
	GetReceiveBufferSize() int
	SetMaxPacketLen(int)
	GetMaxPacketLen() int
	BindPacketFunc(PacketFunc)
	SetConnectType(int)
	SetConn(net.Conn)
	HandlePacket([]byte)

	SetClientClose(ClientClose)
	GetClientClose() ClientClose
	SendJson(head api.JsonHead, funcName string, params ...interface{}) int
	BindPacketFuncJson(callfunc func(packet api.Packet) bool)
	SetPacketParser(I IPacketParser)
	HandlePacketJson(buff []byte)
}

type IWebSocket added in v1.6.3

type IWebSocket interface {
	ISocket

	AssignClientId() uint32
	GetClientById(uint32) IWebSocketClient
}

type IWebSocketClient added in v1.6.3

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
}

-------------- | len | data | --------------

type PacketFunc

type PacketFunc func(packet rpc.Packet) bool //回调函数

type PacketJsonFunc added in v1.9.6

type PacketJsonFunc func(packet api.Packet) bool

type PacketParser

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

-------------- | len | data | --------------

func NewPacketParser

func NewPacketParser(conf PacketConfig) *PacketParser

func (*PacketParser) GetMaxPacketLen added in v1.6.7

func (p *PacketParser) GetMaxPacketLen() int

func (*PacketParser) Read

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

func (*PacketParser) SetMaxPacketLen added in v1.6.7

func (p *PacketParser) SetMaxPacketLen(val int)

func (*PacketParser) Write

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

type PacketParserJson added in v1.7.0

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

-------------- | len | data | --------------

func NewPacketParserJson added in v1.7.0

func NewPacketParserJson(conf PacketConfig) *PacketParserJson

func (*PacketParserJson) GetMaxPacketLen added in v1.7.0

func (p *PacketParserJson) GetMaxPacketLen() int

func (*PacketParserJson) Read added in v1.7.0

func (p *PacketParserJson) Read(buff []byte) bool

func (*PacketParserJson) SetMaxPacketLen added in v1.7.0

func (p *PacketParserJson) SetMaxPacketLen(val int)

func (*PacketParserJson) Write added in v1.7.0

func (p *PacketParserJson) Write(dat []byte) []byte

type ServerSocket

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

func (*ServerSocket) AddClinet

func (s *ServerSocket) AddClinet(conn net.Conn, addr string, connectType int) *ServerSocketClient

func (*ServerSocket) AssignClientId

func (s *ServerSocket) AssignClientId() uint32

func (*ServerSocket) ClientSocket

func (s *ServerSocket) ClientSocket(ctx context.Context) *ServerSocketClient

ClientSocket 给客户发送消息

func (*ServerSocket) Close

func (s *ServerSocket) Close()

func (*ServerSocket) Connect

func (s *ServerSocket) Connect() bool

func (*ServerSocket) DelClinet

func (s *ServerSocket) DelClinet(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 int, 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) SendPacket

func (s *ServerSocket) SendPacket(head rpc.RpcHead, funcName string, packet proto.Message) int

func (*ServerSocket) Start

func (s *ServerSocket) Start() bool

func (*ServerSocket) StopClient

func (s *ServerSocket) StopClient(id uint32)

type ServerSocketClient

type ServerSocketClient struct {
	Socket

	Property any
	// contains filtered or unexported fields
}

func (*ServerSocketClient) Close

func (s *ServerSocketClient) Close()

func (*ServerSocketClient) DoSend

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

func (*ServerSocketClient) GetProperty

func (s *ServerSocketClient) GetProperty() (p any)

获取链接属性

func (*ServerSocketClient) Init

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

func (*ServerSocketClient) OnNetFail

func (s *ServerSocketClient) OnNetFail(error int)

func (*ServerSocketClient) RemoveProperty

func (s *ServerSocketClient) RemoveProperty()

移除链接属性

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) SendMsg

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

func (*ServerSocketClient) SendPacket

func (s *ServerSocketClient) SendPacket(head rpc.RpcHead, funcName string, msg proto.Message) int

func (*ServerSocketClient) SetProperty

func (s *ServerSocketClient) SetProperty(p any)

设置链接属性

func (*ServerSocketClient) Start

func (s *ServerSocketClient) Start() bool

func (*ServerSocketClient) StartJson added in v1.6.7

func (s *ServerSocketClient) StartJson() bool

func (*ServerSocketClient) Stop

func (s *ServerSocketClient) Stop() bool

func (*ServerSocketClient) Update

func (s *ServerSocketClient) Update()

heart

type Socket

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

func (*Socket) BindPacketFunc

func (this *Socket) BindPacketFunc(callfunc PacketFunc)

func (*Socket) BindPacketFuncJson added in v1.6.8

func (s *Socket) BindPacketFuncJson(callfunc PacketJsonFunc)

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) GetClientClose

func (this *Socket) GetClientClose() ClientClose

func (*Socket) GetId

func (this *Socket) GetId() uint32

func (*Socket) GetMaxPacketLen

func (this *Socket) GetMaxPacketLen() int

func (*Socket) GetReceiveBufferSize

func (this *Socket) GetReceiveBufferSize() int

func (*Socket) GetState

func (this *Socket) GetState() int32

func (*Socket) HandlePacket

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

func (*Socket) HandlePacketJson added in v1.7.1

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

func (*Socket) Init

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

virtual

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) SendJson added in v1.8.1

func (this *Socket) SendJson(head api.JsonHead, funcName string, params ...interface{}) int

func (*Socket) SendMsg

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

func (*Socket) SetClientClose

func (this *Socket) SetClientClose(c ClientClose)

func (*Socket) SetConn

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

func (*Socket) SetConnectType

func (this *Socket) SetConnectType(nType int)

func (*Socket) SetMaxPacketLen

func (this *Socket) SetMaxPacketLen(maxReceiveSize int)

func (*Socket) SetPacketParser added in v1.6.7

func (this *Socket) SetPacketParser(I IPacketParser)

func (*Socket) SetReceiveBufferSize

func (this *Socket) SetReceiveBufferSize(maxSendSize int)

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 added in v1.6.3

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

func (*WebSocket) AddClinet added in v1.6.3

func (w *WebSocket) AddClinet(tcpConn *websocket.Conn, addr string, connectType int) *WebSocketClient

func (*WebSocket) AddClinetJson added in v1.8.1

func (w *WebSocket) AddClinetJson(tcpConn *websocket.Conn, addr string, connectType int) IServerSocketClient

func (*WebSocket) AssignClientId added in v1.6.3

func (w *WebSocket) AssignClientId() uint32

func (*WebSocket) Close added in v1.6.3

func (w *WebSocket) Close()

func (*WebSocket) Connect added in v1.6.3

func (w *WebSocket) Connect() bool

func (*WebSocket) DelClient added in v1.6.3

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

func (*WebSocket) Disconnect added in v1.6.3

func (w *WebSocket) Disconnect(bool) bool

func (*WebSocket) GetClientById added in v1.6.3

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

func (*WebSocket) Handler added in v1.8.9

func (sw *WebSocket) Handler(ws *websocket.Conn)

func (*WebSocket) Init added in v1.6.3

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

func (*WebSocket) LoadClient added in v1.6.3

func (w *WebSocket) LoadClient() *WebSocketClient

func (*WebSocket) OnNetFail added in v1.6.3

func (w *WebSocket) OnNetFail(int)

func (*WebSocket) Restart added in v1.6.3

func (w *WebSocket) Restart() bool

func (*WebSocket) Send added in v1.6.3

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

func (*WebSocket) SendJson added in v1.8.8

func (s *WebSocket) SendJson(head api.JsonHead, funcName string, params ...interface{}) int

func (*WebSocket) SendMsg added in v1.6.3

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

func (*WebSocket) ServerWs added in v1.8.9

func (ws *WebSocket) ServerWs(w http.ResponseWriter, r *http.Request)

func (*WebSocket) Start added in v1.6.3

func (w *WebSocket) Start() bool

func (*WebSocket) StopClient added in v1.6.3

func (w *WebSocket) StopClient(id uint32)

type WebSocketClient added in v1.6.3

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

func (*WebSocketClient) Close added in v1.6.3

func (w *WebSocketClient) Close()

func (*WebSocketClient) DoSend added in v1.6.3

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

func (*WebSocketClient) Init added in v1.6.3

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

func (*WebSocketClient) OnNetFail added in v1.6.3

func (w *WebSocketClient) OnNetFail(error int)

func (*WebSocketClient) Run added in v1.6.3

func (w *WebSocketClient) Run() bool

func (*WebSocketClient) Send added in v1.6.3

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

func (*WebSocketClient) SendLoop added in v1.6.3

func (w *WebSocketClient) SendLoop() bool

func (*WebSocketClient) Start added in v1.6.3

func (w *WebSocketClient) Start() bool

func (*WebSocketClient) Stop added in v1.6.3

func (w *WebSocketClient) Stop() bool

func (*WebSocketClient) Update added in v1.6.3

func (w *WebSocketClient) Update() bool

heart

type WebSocketClientJson added in v1.8.1

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

func (*WebSocketClientJson) Close added in v1.8.1

func (w *WebSocketClientJson) Close()

func (*WebSocketClientJson) DoSend added in v1.8.1

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

func (*WebSocketClientJson) Init added in v1.8.1

func (w *WebSocketClientJson) Init(ip string, port int, params ...OpOption) bool

func (*WebSocketClientJson) OnNetFail added in v1.8.1

func (w *WebSocketClientJson) OnNetFail(error int)

func (*WebSocketClientJson) Run added in v1.8.1

func (w *WebSocketClientJson) Run() bool

func (*WebSocketClientJson) Send added in v1.8.1

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

func (*WebSocketClientJson) SendJson added in v1.8.1

func (s *WebSocketClientJson) SendJson(head api.JsonHead, funcName string, params ...interface{}) int

func (*WebSocketClientJson) SendLoop added in v1.8.1

func (w *WebSocketClientJson) SendLoop() bool

func (*WebSocketClientJson) Start added in v1.8.1

func (w *WebSocketClientJson) Start() bool

func (*WebSocketClientJson) Stop added in v1.8.1

func (w *WebSocketClientJson) Stop() bool

func (*WebSocketClientJson) Update added in v1.8.1

func (w *WebSocketClientJson) Update() bool

heart

Jump to

Keyboard shortcuts

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