net

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2022 License: MIT Imports: 9 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source

Functions

func NewConnHandle

func NewConnHandle(con *net.TCPConn) wellConnInterface

Types

type ConnRouter

type ConnRouter struct {
}

TODO 连接路由类

func (*ConnRouter) OnClose

func (this *ConnRouter) OnClose(conn *WellConnection)

func (*ConnRouter) OnConnect

func (this *ConnRouter) OnConnect(conn *WellConnection)

func (*ConnRouter) OnError

func (this *ConnRouter) OnError(err error)

func (*ConnRouter) OnMessage

func (this *ConnRouter) OnMessage(request *WellRequest)

type Group

type Group struct {
}

func (*Group) AddGroup

func (this *Group) AddGroup(GroupName string, Con WellConnection)

将连接对象添加到某个组中

func (*Group) DelGroup

func (this *Group) DelGroup(GroupName string)

删除分组

func (*Group) DelGroupConn

func (this *Group) DelGroupConn(GroupName string, ConnId int64)

移除某个组中的某个连接(并不会关掉连接)

func (*Group) GetAllGroup

func (this *Group) GetAllGroup() []string

获取所有分组的名字

func (*Group) GetAllGroupCon

func (this *Group) GetAllGroupCon(GroupName string) []WellConnection

获取指定分组的所有连接

func (*Group) SendToGroup

func (this *Group) SendToGroup(GroupName string, Data string)

向某个组的所有成员发送信息

type LinkManger

type LinkManger struct {
}
func (this *LinkManger) GetAllLink() map[int64]*WellConnection
func (this *LinkManger) GetLink(Id int64) *WellConnection

func (*LinkManger) SendToAll

func (this *LinkManger) SendToAll(Data string)

func (*LinkManger) SendToId

func (this *LinkManger) SendToId(Id int64, Data string)

type ServerRouter

type ServerRouter struct {
}

TODO 服务路由类

func (*ServerRouter) OnClose

func (this *ServerRouter) OnClose()

func (*ServerRouter) OnStart

func (this *ServerRouter) OnStart()

type WellConnRouter

type WellConnRouter interface {
	OnConnect(conn *WellConnection)
	OnError(err error)
	OnMessage(request *WellRequest)
	OnClose(conn *WellConnection)
}

方法

type WellConnection

type WellConnection struct {
	ConnId int64
	IpAddr string
	Port   string

	LinkManger
	Group
	// contains filtered or unexported fields
}

func (*WellConnection) Close

func (this *WellConnection) Close()

func (*WellConnection) Start

func (this *WellConnection) Start()

func (*WellConnection) WriteByte

func (this *WellConnection) WriteByte(Data []byte)

func (*WellConnection) WriteString

func (this *WellConnection) WriteString(Data string)

type WellMessage

type WellMessage struct {
	Data    []byte
	DataLen uint32
}

信息

func (*WellMessage) GetData

func (this *WellMessage) GetData() []byte

获取消息内容

func (*WellMessage) GetDataLen

func (this *WellMessage) GetDataLen() uint32

获取消息数据段长度

func (*WellMessage) SetData

func (this *WellMessage) SetData(data []byte)

设计消息内容

func (*WellMessage) SetDataLen

func (this *WellMessage) SetDataLen(len uint32)

设置消息数据段长度

type WellMessageInterface

type WellMessageInterface interface {
	GetDataLen() uint32 //获取消息数据段长度
	GetData() []byte    //获取消息内容

	SetData([]byte)    //设置消息内容
	SetDataLen(uint32) //设置消息数据段长度
}

type WellRequest

type WellRequest struct {
	WellConnection
	WellMessage
}

请求封装

type WellServer

type WellServer struct {
	Name         string
	IpAddr       string
	Port         string
	ServerRouter WellServerRouter
	ConnRouter   WellConnRouter
	IpVersion    string
	Version      string

	LinkManger
	Group
	// contains filtered or unexported fields
}

func (*WellServer) AddConnRouter

func (this *WellServer) AddConnRouter(c WellConnRouter)

func (*WellServer) AddServerRouter

func (this *WellServer) AddServerRouter(s WellServerRouter)

func (*WellServer) Close

func (this *WellServer) Close()

func (*WellServer) Groups added in v1.1.10

func (this *WellServer) Groups() *Group
func (this *WellServer) Links() *LinkManger

func (*WellServer) Run

func (this *WellServer) Run()

type WellServerInterface added in v1.2.1

type WellServerInterface interface {
	Run()
	AddServerRouter(s WellServerRouter)
	AddConnRouter(c WellConnRouter)
	Close()
	Groups() *Group
	Links() *LinkManger
}

func NewServerHandle

func NewServerHandle(Name, IpAddr, Port string) WellServerInterface

创建句柄

type WellServerRouter

type WellServerRouter interface {
	OnStart()
	OnClose()
}

Jump to

Keyboard shortcuts

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