network

package
v0.0.0-...-120cf50 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2020 License: GPL-3.0 Imports: 12 Imported by: 0

README

network

网络库

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefultHandShakeTimeout time.Duration = time.Duration(3000) * time.Millisecond //默认握手超时(3000ms)
View Source
var DefultHeaderBytes int = 1024 //默认协议头大小
View Source
var DefultReadTimeout time.Duration = time.Duration(3000) * time.Millisecond //默认读超时(3000ms)
View Source
var DefultWriteTimeout time.Duration = time.Duration(3000) * time.Millisecond //默认写超时(3000ms)
View Source
var PackSize int = 1400 //数据包大小 默认MTU

Functions

func GetMultPartFormData

func GetMultPartFormData(form *multipart.Form, key string) []byte

解析表单文件

func GetMultPartFormValue

func GetMultPartFormValue(form *multipart.Form, key string) string

解析表单数值

func SendBack

func SendBack(w http.ResponseWriter, content string, code int)

返回

func WriteHttp

func WriteHttp(w http.ResponseWriter, data []byte) (int, error)

跨域发送数据

Types

type CliI

type CliI interface {
	SetParam(string, interface{}) error //设置配置
	Dial(string) (SessionI, error)      //拨号
}

type ServerI

type ServerI interface {
	SetParam(string, interface{}) error //设置配置
	Run(wg *sync.WaitGroup)             //服务器跑起来
	Close()                             //关闭
	Type() TYP_NET                      //服务器类型
	Addr() string                       //服务器监听地址
}

type SessionI

type SessionI interface {
	SetParam(string, interface{}) error   //设置配置
	Run() error                           //跑起来
	ReadMsg(arg []byte) (int, error)      //读消息
	WriteMsg(args ...[]byte) (int, error) //写消息
	Close()                               //关闭连接 会等消息发完
	Destroy()                             //摧毁连接 即使有消息也会强制关掉连接
}

type TFConnClose

type TFConnClose func(SessionI)

type TFHandleMsg

type TFHandleMsg func(SessionI, int)

type TFNewConn

type TFNewConn func(SessionI)

type TYP_NET

type TYP_NET string
const (
	TCP  TYP_NET = "tcp"
	UDP  TYP_NET = "udp"
	WS   TYP_NET = "ws"
	HTTP TYP_NET = "http"
)

type TcpCli

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

func NewTcpCli

func NewTcpCli(addr string, f1 TFNewConn, f2 TFHandleMsg, f3 TFConnClose) (*TcpCli, error)

func (*TcpCli) Dial

func (cli *TcpCli) Dial(addr string) (*TcpConn, error)

func (*TcpCli) SetParam

func (cli *TcpCli) SetParam(key string, value interface{}) error

type TcpConn

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

func NewTcpConn

func NewTcpConn(conn net.Conn, f1 TFConnClose, f2 TFHandleMsg) (*TcpConn, error)

func (*TcpConn) Close

func (c *TcpConn) Close()

安全的关闭连接

func (*TcpConn) Destroy

func (c *TcpConn) Destroy()

摧毁连接

func (*TcpConn) IsValid

func (c *TcpConn) IsValid() bool

连接是否可用

func (*TcpConn) ReadMsg

func (c *TcpConn) ReadMsg(arg []byte) (int, error)

读消息(阻塞)

func (*TcpConn) Run

func (c *TcpConn) Run() error

跑起来

func (*TcpConn) SetParam

func (c *TcpConn) SetParam(key string, value interface{}) error

设置参数

func (*TcpConn) WriteMsg

func (c *TcpConn) WriteMsg(args ...[]byte) (int, error)

写消息(阻塞)

type TcpServer

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

func NewTcpServer

func NewTcpServer(addr string, f1 TFNewConn, f2 TFHandleMsg, f3 TFConnClose) (*TcpServer, error)

func (*TcpServer) Addr

func (s *TcpServer) Addr() string

func (*TcpServer) Close

func (s *TcpServer) Close()

func (*TcpServer) Run

func (s *TcpServer) Run(wg *sync.WaitGroup)

func (*TcpServer) SetParam

func (s *TcpServer) SetParam(key string, value interface{}) error

func (*TcpServer) Type

func (s *TcpServer) Type() TYP_NET

type WsCli

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

func NewWsCli

func NewWsCli(addr string, f1 TFNewConn, f2 TFHandleMsg, f3 TFConnClose) (*WsCli, error)

func (*WsCli) Dial

func (cli *WsCli) Dial(url string, opts ...http.Header) (*WsConn, error)

func (*WsCli) SetParam

func (cli *WsCli) SetParam(key string, value interface{}) error

type WsConn

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

func NewWsConn

func NewWsConn(conn *ws.Conn, f1 TFConnClose, f2 TFHandleMsg) (*WsConn, error)

func (*WsConn) Close

func (c *WsConn) Close()

安全的关闭连接

func (*WsConn) Destroy

func (c *WsConn) Destroy()

摧毁连接

func (*WsConn) IsValid

func (c *WsConn) IsValid() bool

连接是否可用

func (*WsConn) ReadMsg

func (c *WsConn) ReadMsg(arg []byte) (int, error)

读消息(阻塞)

func (*WsConn) Run

func (c *WsConn) Run() error

跑起来

func (*WsConn) SetParam

func (c *WsConn) SetParam(key string, value interface{}) error

设置参数

func (*WsConn) WriteMsg

func (c *WsConn) WriteMsg(args ...[]byte) (int, error)

写消息(阻塞)

type WsServer

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

func NewWsServer

func NewWsServer(addr string, f1 TFNewConn, f2 TFHandleMsg, f3 TFConnClose) (*WsServer, error)

func (*WsServer) Addr

func (s *WsServer) Addr() string

func (*WsServer) Close

func (s *WsServer) Close()

func (*WsServer) Run

func (s *WsServer) Run(wg *sync.WaitGroup)

func (*WsServer) ServeHTTP

func (s *WsServer) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*WsServer) SetParam

func (s *WsServer) SetParam(key string, value interface{}) error

func (*WsServer) Type

func (s *WsServer) Type() TYP_NET

Directories

Path Synopsis
test
cli

Jump to

Keyboard shortcuts

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