gtcp

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2021 License: MIT Imports: 3 Imported by: 0

README

使用说明

一. TcpClient

func main() {

//连接参数 1.IP地址  2.缓冲区大小   3.接收签名函数

conn:=gtcp.NewConn("127.0.0.1:7788",1024,msghandler)

//开始连接

conn.Connect()

select {

}

}

//接收数据函数

func msghandler(c *gtcp.ChannelInboundHandler) {

log.Println(string(c.ByteBuffer))

c.Conn.Write([]byte(string(c.ByteBuffer)))  //发送数据

}

二. TcpServer

s:=gtcp.NewServer() //new一个server

ch:=s.MakeTcpChannel("10110",1024,0,msghandler) //配置tcp端口,接收区大小,接收函数

s.BindServer(ch) //绑定通道

s.ListenTcp() //开始监听制定端口

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChannelFuture

type ChannelFuture struct {
	Port           string        //监听端口
	ReadTimeout    time.Duration //服务端读取不到数据超时时间
	BufferSize     int           //缓冲区大小
	ChannelHandler channelHandler
}

通道

type ChannelInboundHandler

type ChannelInboundHandler struct {
	ByteBuffer []byte
	Conn       net.Conn
}

通道入站处理程序

type Conn

type Conn struct {
	Conn       *net.TCPConn
	ByteBuffer []byte
	Addr       string
	Ch         channelHandler
	H          *ChannelInboundHandler
}

func NewConn

func NewConn(addr string, buffersize int, h channelHandler) *Conn

func (*Conn) Connect

func (c *Conn) Connect() error

type TcpServer

type TcpServer struct {
	ChannelFutures []*ChannelFuture //socket通道切片
	Address        string           //监听IP地址
}

func NewServer

func NewServer() *TcpServer

func (*TcpServer) BindServer

func (s *TcpServer) BindServer(channels ...*ChannelFuture)

绑定服务

func (*TcpServer) ListenTcp

func (s *TcpServer) ListenTcp()

设置TCP监听地址

func (*TcpServer) MakeTcpChannel

func (s *TcpServer) MakeTcpChannel(port string, bufferSize int, readTimeout time.Duration, handler channelHandler) *ChannelFuture

Jump to

Keyboard shortcuts

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