network

package
v0.0.0-...-1c597ed Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2020 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const HeaderLen uint32 = 4

Variables

View Source
var (
	GET_METHOD    = "GET"
	POST_METHOD   = "POST"
	SENDTYPE_FORM = "form"
	SENDTYPE_JSON = "json"
)

Functions

func GetUrlBuild

func GetUrlBuild(link string, data map[string]string) string

Types

type Agent

type Agent interface {
	Run()
	OnClose()
}

type Conn

type Conn interface {
	// Read() (int, []byte, error)
	Read(b []byte) (n int, err error)
	Write(b []byte)
	ReadMsg() (*common.WorldPacket, error)     //会对包头处理
	WriteMsg(packet *common.WorldPacket) error //会对包头处理
	LocalAddr() net.Addr
	RemoteAddr() net.Addr
	Close()
	IsClosed() bool
	InitCrypt(k []byte)
}

type ConnSet

type ConnSet map[net.Conn]struct{}

ConnSet server conn map

type HttpSend

type HttpSend struct {
	Link     string
	SendType string
	Header   map[string]string
	Body     map[string]string
	sync.RWMutex
}

func NewHttpSend

func NewHttpSend(link string) *HttpSend

func (*HttpSend) Get

func (h *HttpSend) Get() ([]byte, error)

func (*HttpSend) Post

func (h *HttpSend) Post() ([]byte, error)

func (*HttpSend) SetBody

func (h *HttpSend) SetBody(body map[string]string)

func (*HttpSend) SetHeader

func (h *HttpSend) SetHeader(header map[string]string)

func (*HttpSend) SetSendType

func (h *HttpSend) SetSendType(send_type string)

type KKHandle

type KKHandle interface {
	ServeHTTP(w http.ResponseWriter, r *http.Request)
	Close()
}

type TCPClient

type TCPClient struct {
	sync.Mutex
	Addr            string
	ConnNum         int
	ConnectInterval time.Duration
	AutoReconnect   bool
	NewAgent        func(*TCPConn) Agent

	// msg parser
	LenMsgLen    int
	MinMsgLen    uint32
	MaxMsgLen    uint32
	LittleEndian bool
	// contains filtered or unexported fields
}

func (*TCPClient) Close

func (client *TCPClient) Close()

func (*TCPClient) IsClosed

func (client *TCPClient) IsClosed() bool

func (*TCPClient) Start

func (client *TCPClient) Start()

type TCPConn

type TCPConn struct {
	Crypt auth.AuthCrypt
	// contains filtered or unexported fields
}

TCPConn tcp连接类

func (*TCPConn) Close

func (tcpConn *TCPConn) Close()

func (*TCPConn) DirectWrite

func (tcpConn *TCPConn) DirectWrite(b []byte)

不进队列,直接发送

func (*TCPConn) InitCrypt

func (tcpConn *TCPConn) InitCrypt(k []byte)

func (*TCPConn) IsClosed

func (tcpConn *TCPConn) IsClosed() bool

func (*TCPConn) LocalAddr

func (tcpConn *TCPConn) LocalAddr() net.Addr

func (*TCPConn) Read

func (tcpConn *TCPConn) Read(b []byte) (n int, err error)

func (*TCPConn) ReadMsg

func (tcpConn *TCPConn) ReadMsg() (*common.WorldPacket, error)

func (*TCPConn) RemoteAddr

func (tcpConn *TCPConn) RemoteAddr() net.Addr

func (*TCPConn) Write

func (tcpConn *TCPConn) Write(b []byte)

func (*TCPConn) WriteMsg

func (tcpConn *TCPConn) WriteMsg(packet *common.WorldPacket) error

type TCPServer

type TCPServer struct {
	Addr       string
	MaxConnNum int
	NewAgent   func(*TCPConn) Agent
	MaxMsgLen  uint32
	// contains filtered or unexported fields
}

TCPServer TCP server manager

func (*TCPServer) Close

func (server *TCPServer) Close()

func (*TCPServer) Start

func (server *TCPServer) Start()

Start start server

type WSConn

type WSConn struct {
	Crypt auth.AuthCrypt
	// contains filtered or unexported fields
}

func (*WSConn) Close

func (wsConn *WSConn) Close()

func (*WSConn) DirectWrite

func (wsConn *WSConn) DirectWrite(b []byte)

不进队列,直接发送

func (*WSConn) InitCrypt

func (wsConn *WSConn) InitCrypt(k []byte)

func (*WSConn) IsClosed

func (wsConn *WSConn) IsClosed() bool

func (*WSConn) LocalAddr

func (wsConn *WSConn) LocalAddr() net.Addr

func (*WSConn) Read

func (wsConn *WSConn) Read(b []byte) (n int, err error)

func (*WSConn) ReadMsg

func (wsConn *WSConn) ReadMsg() (*common.WorldPacket, error)

func (*WSConn) RemoteAddr

func (wsConn *WSConn) RemoteAddr() net.Addr

func (*WSConn) Write

func (wsConn *WSConn) Write(b []byte)

func (*WSConn) WriteMsg

func (wsConn *WSConn) WriteMsg(packet *common.WorldPacket) error

args must not be modified by the others goroutines

type WSServer

type WSServer struct {
	Addr        string
	MaxConnNum  int
	MaxMsgLen   uint32
	HTTPTimeout time.Duration
	CertFile    string
	KeyFile     string
	NewAgent    func(*Conn) Agent

	Handler *KKHandle
	// contains filtered or unexported fields
}

func (*WSServer) Close

func (server *WSServer) Close()

func (*WSServer) Start

func (server *WSServer) Start()

type WsConnSet

type WsConnSet map[*websocket.Conn]struct{}

Jump to

Keyboard shortcuts

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