gotcp

package module
v0.0.0-...-6337d12 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2015 License: MIT Imports: 9 Imported by: 0

README

gotcp

A Go package for quickly building tcp servers

Usage

###Install

go get github.com/gansidui/gotcp

###Examples

Document

Doc

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrConnClosing   = errors.New("use of closed network connection")
	ErrWriteBlocking = errors.New("write packet was blocking")
	ErrReadBlocking  = errors.New("read packet was blocking")
	ErrReadHalf      = errors.New("read half packet")
)

Error type

Functions

This section is empty.

Types

type Config

type Config struct {
	PacketSendChanLimit    uint32 // the limit of packet send channel
	PacketReceiveChanLimit uint32 // the limit of packet receive channel
}

type Conn

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

Conn exposes a set of callbacks for the various events that occur on a connection

func (*Conn) AsyncReadPacket

func (c *Conn) AsyncReadPacket(timeout time.Duration) (Packet, error)

AsyncReadPacket async reads a packet, this method will never block

func (*Conn) AsyncWritePacket

func (c *Conn) AsyncWritePacket(p Packet, timeout time.Duration) error

AsyncWritePacket async writes a packet, this method will never block

func (*Conn) Close

func (c *Conn) Close()

Close closes the connection

func (*Conn) Do

func (c *Conn) Do()

Do it

func (*Conn) GetExtraData

func (c *Conn) GetExtraData() interface{}

GetExtraData gets the extra data from the Conn

func (*Conn) GetIndex

func (c *Conn) GetIndex() uint32

func (*Conn) GetMac

func (c *Conn) GetMac() string

func (*Conn) GetRawConn

func (c *Conn) GetRawConn() *net.TCPConn

GetRawConn returns the raw net.TCPConn from the Conn

func (*Conn) GetRecvBytes

func (c *Conn) GetRecvBytes() *bytes.Buffer

func (*Conn) GetTopic

func (c *Conn) GetTopic() string

func (*Conn) IsClosed

func (c *Conn) IsClosed() bool

IsClosed indicates whether or not the connection is closed

func (*Conn) NsqWritePacket

func (c *Conn) NsqWritePacket(p Packet, timeout time.Duration) error

func (*Conn) PutExtraData

func (c *Conn) PutExtraData(data interface{})

PutExtraData puts the extra data with the Conn

func (*Conn) Send

func (c *Conn) Send(topic string, value []byte) bool

func (*Conn) SetID

func (c *Conn) SetID(mac string, index uint32) error

func (*Conn) SetMac

func (c *Conn) SetMac(mac string)

func (*Conn) SetTimeFlag

func (c *Conn) SetTimeFlag(timeflag int64)

func (*Conn) SetTopic

func (c *Conn) SetTopic(topic string)

type ConnCallback

type ConnCallback interface {
	// OnConnect is called when the connection was accepted,
	// If the return value of false is closed
	OnConnect(*Conn) bool

	// OnMessage is called when the connection receives a packet,
	// If the return value of false is closed
	OnMessage(*Conn, Packet) bool

	// OnClose is called when the connection closed
	OnClose(*Conn)
}

ConnCallback is an interface of methods that are used as callbacks on a connection

type MqConfig

type MqConfig struct {
	Addr    string
	Topic   string
	Channel string
}

type Mqhub

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

func Newmqhub

func Newmqhub(config *MqConfig, protocol Protocol) *Mqhub

func (*Mqhub) Exist

func (q *Mqhub) Exist(id string) bool

func (*Mqhub) GetAddr

func (q *Mqhub) GetAddr() string

func (*Mqhub) GetConn

func (q *Mqhub) GetConn(mac string) *Conn

func (*Mqhub) RemoveConn

func (q *Mqhub) RemoveConn(index uint32, mac string)

func (*Mqhub) Send

func (q *Mqhub) Send(topic string, value []byte) error

func (*Mqhub) Start

func (q *Mqhub) Start()

func (*Mqhub) Stop

func (q *Mqhub) Stop()

type Packet

type Packet interface {
	Serialize() []byte
}

type Protocol

type Protocol interface {
	ReadPacket(conn *Conn) (Packet, error)
}

type Server

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

func NewServer

func NewServer(config *Config, callback ConnCallback, protocol Protocol, mqhub *Mqhub) *Server

NewServer creates a server

func (*Server) Start

func (s *Server) Start(listener *net.TCPListener, acceptTimeout time.Duration)

Start starts service

func (*Server) Stop

func (s *Server) Stop()

Stop stops service

Directories

Path Synopsis
examples
das

Jump to

Keyboard shortcuts

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