channel

package
v0.0.0-...-cf517e0 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2017 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

分帧器

Index

Constants

View Source
const (
	BufSize = 32
)

Variables

View Source
var (
	Ping = []byte("ping")
	Pong = []byte("pong")
)
View Source
var (
	Err_CloseByPong  = errors.New("long time no pong")
	Err_CloseByPing  = errors.New("long time no ping")
	Err_CloseDefault = errors.New("closed")
)

Functions

This section is empty.

Types

type Channel

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

解决粘包等问题,以及心跳

func FromKcpConn

func FromKcpConn(conn *kcp.UDPSession, protoCoder ProtoCol) *Channel

func FromReadWriteCloser

func FromReadWriteCloser(conn ReadWriteCloser) *Channel

从连接得到有个新管道, 如果没有可用的协程服务连接则会阻塞

func FromTcpConn

func FromTcpConn(conn *net.TCPConn, protoCoder ProtoCol) *Channel

func FromWsConn

func FromWsConn(conn *websocket.Conn) *Channel

func (*Channel) CheckPing

func (p *Channel) CheckPing(duration time.Duration)

检测客户端一定时间有无ping, 若没有就关闭连接, duration为0则不检查 用于服务端

func (*Channel) CheckPong

func (p *Channel) CheckPong(duration time.Duration)

检测服务器一定时间有无pong, 若没有就关闭连接, duration为0则不检查 用于客户端

func (*Channel) Close

func (p *Channel) Close(reason error) (err error)

关闭连接, Write和Read的阻塞将会打破 并返回错误

func (*Channel) Read

func (p *Channel) Read() (bs []byte, err error)

func (*Channel) SetValue

func (p *Channel) SetValue(key string, value interface{})

func (*Channel) StartPing

func (p *Channel) StartPing(duration time.Duration)

启动ping, 定时写入Ping消息 用于客户端

func (*Channel) Value

func (p *Channel) Value(key string) (value interface{}, ok bool)

func (*Channel) Write

func (p *Channel) Write(bs []byte) (err error)

func (*Channel) WriteSync

func (p *Channel) WriteSync(bs []byte) (err error)

type Kcp

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

func (*Kcp) Close

func (p *Kcp) Close() (err error)

func (*Kcp) ReadFrame

func (p *Kcp) ReadFrame() (bs []byte, err error)

func (*Kcp) WriteFrame

func (p *Kcp) WriteFrame(bs []byte) (err error)

type LenProtoCol

type LenProtoCol struct {
}

第一个字节是头长度1:uint8, 2:uint16, 4:uint32 后面x个的是内容长度 在后面是内容

func (*LenProtoCol) Read

func (p *LenProtoCol) Read(reader io.Reader) ([]byte, error)

func (*LenProtoCol) Write

func (p *LenProtoCol) Write(writer io.Writer, data []byte) (int, error)

type ProtoCol

type ProtoCol interface {
	Read(io.Reader) ([]byte, error)       // 从一个流里读取一帧
	Write(io.Writer, []byte) (int, error) // 将一帧写入流
}

func NewLenProtoCol

func NewLenProtoCol() ProtoCol

type ReadWriteCloser

type ReadWriteCloser interface {
	ReadFrame() ([]byte, error)
	WriteFrame([]byte) error
	Close() error
}

type Tcp

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

func (*Tcp) Close

func (p *Tcp) Close() (err error)

func (*Tcp) ReadFrame

func (p *Tcp) ReadFrame() (bs []byte, err error)

func (*Tcp) WriteFrame

func (p *Tcp) WriteFrame(bs []byte) (err error)

type Ws

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

func (*Ws) Close

func (p *Ws) Close() error

func (*Ws) ReadFrame

func (p *Ws) ReadFrame() (bs []byte, err error)

func (*Ws) WriteFrame

func (p *Ws) WriteFrame(bs []byte) (err error)

Jump to

Keyboard shortcuts

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