network

package
v0.0.0-...-fe0cef8 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2018 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandleClient

func HandleClient(conn net.Conn, h Handler) io.WriteCloser

HandleClient 处理连接

func Marshal

func Marshal(w io.Writer, obj interface{}) (int, error)

Marshal 序列化

func Packet

func Packet(w io.Writer, size, id uint16, v ...interface{}) error

Packet 协议包

func TODO

func TODO(data []byte, c io.Writer) error

TODO 空任务

func Unmarshal

func Unmarshal(data []byte, v interface{}) (int, error)

Unmarshal 反序列化

Types

type Conn

type Conn struct {
	sync.Map
	// contains filtered or unexported fields
}

Conn 连接对象

func NewClient

func NewClient(conn net.Conn) *Conn

NewClient 处理连接

func (*Conn) Close

func (c *Conn) Close() error

Close 关闭连接

func (*Conn) Run

func (c *Conn) Run(h Handler)

Run 读线程

func (*Conn) String

func (c *Conn) String() string

String 实现接口 Stringer

func (*Conn) Write

func (c *Conn) Write(s []byte) (int, error)

Write 实现 io.Writer

type HandleFunc

type HandleFunc func(data []byte, c *Conn) error

HandleFunc 消息回调

func (HandleFunc) Serve

func (f HandleFunc) Serve(data []byte, c *Conn) error

Serve 处理消息

type Handler

type Handler interface {
	Serve(data []byte, c *Conn) error
}

Handler 消息处理

type Route

type Route map[uint16]Handler

Route 路由

func (Route) Handle

func (r Route) Handle(id uint16, f HandleFunc)

Handle 处理消息

func (Route) Serve

func (r Route) Serve(data []byte, c *Conn) error

Serve 处理消息

Jump to

Keyboard shortcuts

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