network

package
v0.0.0-...-0dc63de Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NetTypeTcp       = "tcp"
	NetTypeWebSocket = "webSocket"
	// todo udp
	NetTypeKcp = "kcp" // todo kcp
)
View Source
const (
	DisConnectTypeBroken = 0 // 默认网络断开
)

Variables

View Source
var (
	// tcp监听地址错误
	ErrListenAddrError = errors.TempErr("ListenAddr netType[%s] addr[%s] err : %s")
	// tcp监听创建监听错误
	ErrCreateListenError = errors.TempErr("Create listen netType[%s] addr[%s] err : %s")
	// 链接读超时
	ErrTcpLinkReadTimeOutError = errors.TempErr("Tcp link read tyimeout")

	/* 断开链接 */
	ErrLinkDisconnect = errors.TempErr("broken link: netType:%s brokenType:%d")

	/* webSocket */
	ErrWsRouting = errors.TempErr("web socket route[%v] err: %s")
)

Functions

This section is empty.

Types

type KcpClient

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

func NewKcpClient

func NewKcpClient(parent context.Context, host string) (*KcpClient, error)

func (*KcpClient) Close

func (tc *KcpClient) Close(brokenType int)

Close 关闭

func (*KcpClient) CloseCallBack

func (tc *KcpClient) CloseCallBack()

CloseCallBack 关闭回调

func (*KcpClient) Dispatch

func (tc *KcpClient) Dispatch(data []byte)

func (*KcpClient) NetType

func (tc *KcpClient) NetType() string

func (*KcpClient) Read

func (tc *KcpClient) Read(p []byte) (int, error)

Read : io.Reader realize

func (*KcpClient) ReadPack

func (tc *KcpClient) ReadPack() ([]byte, error)

ReadPack 读取数据包

func (*KcpClient) Start

func (tc *KcpClient) Start()

Start 启动

func (*KcpClient) Write

func (tc *KcpClient) Write(data []byte) (int, error)

Write : io.Writer realize

type KcpLink struct {
	// contains filtered or unexported fields
}
func NewKcpLink(parent context.Context, netType string, fd net.Conn, listenServer ListenServer) *KcpLink

func (*KcpLink) Close

func (tl *KcpLink) Close(brokenType int)

Close 关闭

func (*KcpLink) CloseCallBack

func (tl *KcpLink) CloseCallBack()

CloseCallBack 关闭回调

func (*KcpLink) ID

func (tl *KcpLink) ID() uint

ID 唯一标识性信息

func (*KcpLink) MsgCount

func (tl *KcpLink) MsgCount() uint64

func (*KcpLink) NetType

func (tl *KcpLink) NetType() string

NetType 获取网络类型

func (*KcpLink) Read

func (tl *KcpLink) Read(p []byte) (int, error)

Read : io.Reader realize

func (*KcpLink) ReadPack

func (tl *KcpLink) ReadPack() ([]byte, error)

ReadPack 读取数据包

func (*KcpLink) Start

func (tl *KcpLink) Start()

Start 启动

func (*KcpLink) Write

func (tl *KcpLink) Write(data []byte) (int, error)

Write : io.Writer realize

type KcpListenServer

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

KcpListenServer tcp服务

func NewKcpListenServer

func NewKcpListenServer(parent context.Context, address string, _ ...any) (*KcpListenServer, error)
func (b KcpListenServer) AddLink(linkObj Link)

func (KcpListenServer) Close

func (b KcpListenServer) Close()

func (KcpListenServer) CloseCallBack

func (b KcpListenServer) CloseCallBack()
func (b KcpListenServer) CloseLink(linkObj Link, brokenType int)

func (KcpListenServer) CloseLinkByID

func (b KcpListenServer) CloseLinkByID(id uint, brokenType int)

func (KcpListenServer) Ctx

func (b KcpListenServer) Ctx() context.Context
func (b KcpListenServer) DelLink(linkObj Link, brokenType int)

func (KcpListenServer) Dispatch

func (b KcpListenServer) Dispatch(id uint, bs []byte)

Dispatch 数据派发: 链接获取到的数据进行派发

func (b KcpListenServer) GetLink(id uint) Link

func (KcpListenServer) GetListen

func (b KcpListenServer) GetListen() net.Listener

func (KcpListenServer) LinkCount

func (b KcpListenServer) LinkCount() int

func (KcpListenServer) NetType

func (b KcpListenServer) NetType() string

func (KcpListenServer) SendData

func (b KcpListenServer) SendData(id uint, data []byte)

func (*KcpListenServer) Start

func (t *KcpListenServer) Start()
type Link interface {
	io.Writer // 数据写入
	NetType() string
	ReadPack() ([]byte, error) // 读取数据包
	ID() uint                  // 唯一id标识
	Start()                    // 启动
	Close(brokenType int)      // 关闭 brokenType:关闭类型
	CloseCallBack()            // 关闭回调
}

type ListenServer

type ListenServer interface {
	Ctx() context.Context    // 获取ctx
	GetListen() net.Listener // 获取底层监听器
	NetType() string         // 获取网络类型(tcp等)
	CloseCallBack()          // 关闭回调

	/* 管理 */
	AddLink(linkObj Link)                   // 添加链接
	GetLink(id uint) Link                   // 获取链接
	DelLink(linkObj Link, brokenType int)   // 删除链接
	CloseLink(linkObj Link, brokenType int) // 关闭链接:先关闭后删除
	CloseLinkByID(id uint, brokenType int)  // 关闭链接(id索引):先关闭后删除
	Dispatch(id uint, bs []byte)            // 数据派发
	LinkCount() int                         // 当前拥有的链接数量
	SendData(id uint, data []byte)          // 发送数据

	/* 服务 */
	Start()
	Close()
}

func NewListen

func NewListen(parent context.Context, netType string, address string, parmas ...any) (ListenServer, error)

type TcpClient

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

func NewTcpClient

func NewTcpClient(parent context.Context, host string) (*TcpClient, error)

func (*TcpClient) Close

func (tc *TcpClient) Close(brokenType int)

Close 关闭

func (*TcpClient) CloseCallBack

func (tc *TcpClient) CloseCallBack()

CloseCallBack 关闭回调

func (*TcpClient) Dispatch

func (tc *TcpClient) Dispatch(data []byte)

func (*TcpClient) NetType

func (tc *TcpClient) NetType() string

func (*TcpClient) Read

func (tc *TcpClient) Read(p []byte) (int, error)

Read : io.Reader realize

func (*TcpClient) ReadPack

func (tc *TcpClient) ReadPack() ([]byte, error)

ReadPack 读取数据包

func (*TcpClient) Start

func (tc *TcpClient) Start()

Start 启动

func (*TcpClient) Write

func (tc *TcpClient) Write(data []byte) (int, error)

Write : io.Writer realize

type TcpLink struct {
	// contains filtered or unexported fields
}
func NewTcpLink(parent context.Context, netType string, fd net.Conn, listenServer ListenServer) *TcpLink

func (*TcpLink) Close

func (tl *TcpLink) Close(brokenType int)

Close 关闭

func (*TcpLink) CloseCallBack

func (tl *TcpLink) CloseCallBack()

CloseCallBack 关闭回调

func (*TcpLink) ID

func (tl *TcpLink) ID() uint

ID 唯一标识性信息

func (*TcpLink) MsgCount

func (tl *TcpLink) MsgCount() uint64

func (*TcpLink) NetType

func (tl *TcpLink) NetType() string

NetType 获取网络类型

func (*TcpLink) Read

func (tl *TcpLink) Read(p []byte) (int, error)

Read : io.Reader realize

func (*TcpLink) ReadPack

func (tl *TcpLink) ReadPack() ([]byte, error)

ReadPack 读取数据包

func (*TcpLink) Start

func (tl *TcpLink) Start()

Start 启动

func (*TcpLink) Write

func (tl *TcpLink) Write(data []byte) (int, error)

Write : io.Writer realize

type TcpListenServer

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

TcpListenServer tcp服务

func NewTcpListenServer

func NewTcpListenServer(parent context.Context, address string, _ ...any) (*TcpListenServer, error)
func (b TcpListenServer) AddLink(linkObj Link)

func (TcpListenServer) Close

func (b TcpListenServer) Close()

func (TcpListenServer) CloseCallBack

func (b TcpListenServer) CloseCallBack()
func (b TcpListenServer) CloseLink(linkObj Link, brokenType int)

func (TcpListenServer) CloseLinkByID

func (b TcpListenServer) CloseLinkByID(id uint, brokenType int)

func (TcpListenServer) Ctx

func (b TcpListenServer) Ctx() context.Context
func (b TcpListenServer) DelLink(linkObj Link, brokenType int)

func (TcpListenServer) Dispatch

func (b TcpListenServer) Dispatch(id uint, bs []byte)

Dispatch 数据派发: 链接获取到的数据进行派发

func (b TcpListenServer) GetLink(id uint) Link

func (TcpListenServer) GetListen

func (b TcpListenServer) GetListen() net.Listener

func (TcpListenServer) LinkCount

func (b TcpListenServer) LinkCount() int

func (TcpListenServer) NetType

func (b TcpListenServer) NetType() string

func (TcpListenServer) SendData

func (b TcpListenServer) SendData(id uint, data []byte)

func (*TcpListenServer) Start

func (t *TcpListenServer) Start()

type WebSocketClient

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

func NewWebScoketClient

func NewWebScoketClient(parent context.Context, host, routing string) (*WebSocketClient, error)

func (*WebSocketClient) Close

func (wc *WebSocketClient) Close(brokenType int)

Close 关闭

func (*WebSocketClient) CloseCallBack

func (wc *WebSocketClient) CloseCallBack()

CloseCallBack 关闭回调

func (*WebSocketClient) Dispatch

func (wc *WebSocketClient) Dispatch(data []byte)

func (*WebSocketClient) NetType

func (wc *WebSocketClient) NetType() string

func (*WebSocketClient) ReadPack

func (wc *WebSocketClient) ReadPack() ([]byte, error)

ReadPack 读取数据包

func (*WebSocketClient) Start

func (wc *WebSocketClient) Start()

func (*WebSocketClient) Write

func (wc *WebSocketClient) Write(data []byte) (int, error)

Write : io.Writer realize

type WebSocketLink struct {
	// contains filtered or unexported fields
}
func NewWebSocketLink(parent context.Context, fd *websocket.Conn, listenServer ListenServer) *WebSocketLink

func (*WebSocketLink) Close

func (wl *WebSocketLink) Close(brokenType int)

Close 关闭

func (*WebSocketLink) CloseCallBack

func (wl *WebSocketLink) CloseCallBack()

CloseCallBack 关闭回调

func (*WebSocketLink) ID

func (wl *WebSocketLink) ID() uint

ID 唯一标识性信息

func (*WebSocketLink) MsgCount

func (wl *WebSocketLink) MsgCount() uint64

func (*WebSocketLink) NetType

func (wl *WebSocketLink) NetType() string

NetType 获取网络类型

func (*WebSocketLink) ReadPack

func (wl *WebSocketLink) ReadPack() ([]byte, error)

ReadPack 读取数据包

func (*WebSocketLink) Start

func (wl *WebSocketLink) Start()

func (*WebSocketLink) Write

func (wl *WebSocketLink) Write(data []byte) (int, error)

Write : io.Writer realize

type WebSocketListenServer

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

WebSocketListenServer webSocket服务

func NewWebSocketListenServer

func NewWebSocketListenServer(parent context.Context, address string, parmas ...any) (*WebSocketListenServer, error)
func (b WebSocketListenServer) AddLink(linkObj Link)

func (WebSocketListenServer) Close

func (b WebSocketListenServer) Close()

func (WebSocketListenServer) CloseCallBack

func (b WebSocketListenServer) CloseCallBack()
func (b WebSocketListenServer) CloseLink(linkObj Link, brokenType int)

func (WebSocketListenServer) CloseLinkByID

func (b WebSocketListenServer) CloseLinkByID(id uint, brokenType int)

func (WebSocketListenServer) Ctx

func (b WebSocketListenServer) Ctx() context.Context
func (b WebSocketListenServer) DelLink(linkObj Link, brokenType int)

func (WebSocketListenServer) Dispatch

func (b WebSocketListenServer) Dispatch(id uint, bs []byte)

Dispatch 数据派发: 链接获取到的数据进行派发

func (b WebSocketListenServer) GetLink(id uint) Link

func (WebSocketListenServer) GetListen

func (b WebSocketListenServer) GetListen() net.Listener

func (WebSocketListenServer) LinkCount

func (b WebSocketListenServer) LinkCount() int

func (WebSocketListenServer) NetType

func (b WebSocketListenServer) NetType() string

func (WebSocketListenServer) SendData

func (b WebSocketListenServer) SendData(id uint, data []byte)

func (*WebSocketListenServer) Start

func (w *WebSocketListenServer) Start()

Directories

Path Synopsis
test

Jump to

Keyboard shortcuts

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