gtcp

package
v0.0.0-...-c9a36a8 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2018 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

TCP服务端

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Checksum

func Checksum(buffer []byte) uint32

常见的二进制数据校验方式,生成校验结果

func Conn

func Conn(ip string, port int, timeout ...int) (net.Conn, error)

创建TCP链接

func Receive

func Receive(conn net.Conn, retry ...Retry) ([]byte, error)

获取数据

func ReceiveWithTimeout

func ReceiveWithTimeout(conn net.Conn, timeout time.Duration, retry ...Retry) ([]byte, error)

带超时时间的数据获取

func Send

func Send(conn net.Conn, data []byte, retry ...Retry) error

发送数据

func SendReceive

func SendReceive(conn net.Conn, data []byte, retry ...Retry) ([]byte, error)

发送数据并等待接收返回数据

func SendReceiveWithTimeout

func SendReceiveWithTimeout(conn net.Conn, data []byte, timeout time.Duration, retry ...Retry) ([]byte, error)

发送数据并等待接收返回数据(带返回超时等待时间)

func SendWithTimeout

func SendWithTimeout(conn net.Conn, data []byte, timeout time.Duration, retry ...Retry) error

带超时时间的数据发送

Types

type Retry

type Retry struct {
	Count    int // 重试次数
	Interval int // 重试间隔(毫秒)
}

type Server

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

tcp server结构体

func GetServer

func GetServer(name ...interface{}) *Server

获取/创建一个空配置的TCP Server 单例模式,请保证name的唯一性

func NewServer

func NewServer(address string, handler func(net.Conn), names ...string) *Server

创建一个tcp server对象,并且可以选择指定一个单例名字

func (*Server) Run

func (s *Server) Run() error

执行监听

func (*Server) SetAddress

func (s *Server) SetAddress(address string)

设置参数 - address

func (*Server) SetHandler

func (s *Server) SetHandler(handler func(net.Conn))

设置参数 - handler

Jump to

Keyboard shortcuts

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