tcp

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: May 12, 2020 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Accept

func Accept(server TcpServer, event Event)

onConnect func(conn Connection), onReceive func(conn Connection, buffer []byte), onClose func(conn Connection) 封装tcp连接池管理

func Connect

func Connect(conn Connection, onConnect func(conn Connection),
	onReceive func(conn Connection, buffer []byte), onClose func(conn Connection))

新连接

Types

type Client

type Client struct {
	Conn  []Connection
	Count uint32 //连接数量
	// contains filtered or unexported fields
}

客户端连接池

var Clients Client

func (*Client) GetPoolIndex

func (c *Client) GetPoolIndex() uint32

获取连接池自增Id并加一

type Connection

type Connection struct {
	Fd     uint32
	Addr   string
	Socket net.Conn // 底层websocket
	// contains filtered or unexported fields
}

Tcp连接

func (*Connection) Close

func (conn *Connection) Close() error

关闭socket连接

func (*Connection) Read

func (conn *Connection) Read(buffer []byte) error

ws连接获取消息

func (*Connection) Write

func (conn *Connection) Write(data []byte) error

ws连接发送消息

type Event

type Event struct {
	OnConnect func(conn Connection)
	OnReceive func(conn Connection, buffer []byte)
	OnClose   func(conn Connection)
}

type TcpServer

type TcpServer struct {
	Listen net.Listener
}

func Listen

func Listen(network string, addr string) (server TcpServer, err error)

监听tcp端口

Jump to

Keyboard shortcuts

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