net

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TCP_STATE_CONNECTED    = iota //连接成功
	TCP_STATE_DISCONNECTED        //客户端正常退出
	TCP_STATE_DATA                //接收到数据
	TCP_STATE_ERROR               //服务器accept错误/客户端异常退出(可能服务器异常关闭)/客户端连接失败(即客户端)
)

Variables

This section is empty.

Functions

func ReadPackage

func ReadPackage(conn net.Conn) ([]byte, error)

2byte length + data

func ReadUint16

func ReadUint16(conn net.Conn) (uint16, error)

read 4byte data

func WritePackage

func WritePackage(conn net.Conn, data []byte) error

2byte+[]data,确保数据完整被发送。

Types

type StateCall

type StateCall func(conn net.Conn, state uint8, data []byte, datasize uint16, err error)

type TcpClient

type TcpClient struct {
	Conn            net.Conn
	OnEvent         StateCall
	AutoCon         bool
	AutoConnectChan chan int
}

/////////////////////////////////////////////////////////////////////

func NewTcpClient

func NewTcpClient() *TcpClient

func (*TcpClient) AutoConnectServer

func (c *TcpClient) AutoConnectServer(addr string)

支持断开后自动重连

func (*TcpClient) DisableAutoConnect

func (c *TcpClient) DisableAutoConnect()

拒绝自动重新连接。

func (*TcpClient) LoopReceive

func (c *TcpClient) LoopReceive() error

func (*TcpClient) Release

func (c *TcpClient) Release()

释放客户端

type TcpServer

type TcpServer struct {
	Port    uint16
	OnEvent StateCall
}

func NewTcpServer

func NewTcpServer() *TcpServer

func (*TcpServer) Start

func (s *TcpServer) Start(port uint16) error

在协程里执行接收连接,且每个连接为一个协程

Source Files

  • net.go

Jump to

Keyboard shortcuts

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