client

package
v0.0.0-...-d436db8 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2020 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ChatroomServiceID = 10000006

	PayloadQuery = 101 // 查询聊天室信息
	PayloadJoin  = 102 // 加入聊天室
	PayloadQuit  = 103 // 退出聊天室

	PayloadIncomingMsg = 1000 // 消息通知
	PayloadCompressed  = 1003 // 压缩消息
)
View Source
const (
	StateIdle = iota
	StateRunning
	StateInitiated
	StateLoggedIn
)
View Source
const (
	Tcp       = "tcp"
	WebSocket = "ws"

	ConnTimeout    = 5
	WriteTimeout   = 20
	RequestTimeout = 30
	ClientChanLen  = 100
)
View Source
const (
	IM       = "im"
	Peer     = "peer"
	Public   = "public"
	ChatRoom = "chatroom"
)
View Source
const (
	GroupServiceID = 10000001
)

Variables

View Source
var (
	PingData = []byte{0, 0, 0, 0}
)

Functions

func Http

func Http(tag string, cmds []string)

func Log

func Log(tag, id string, args ...interface{})

Types

type AccountInfo

type AccountInfo struct {
	UserID    string // User ID
	Password  string // Corresponding password
	Signature string // Signature to obtain token
	DeviceID  string // Device ID
	Platform  string // Platform
}

type ChatroomService

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

func (*ChatroomService) GetMultiInfo

func (this *ChatroomService) GetMultiInfo(args []string)

func (*ChatroomService) HandleGetMessage

func (this *ChatroomService) HandleGetMessage(msg *UserMessage) bool

func (*ChatroomService) HandleServiceMessage

func (this *ChatroomService) HandleServiceMessage(data []byte, sn uint64, source int) bool

func (*ChatroomService) Join

func (this *ChatroomService) Join(args []string) bool

func (*ChatroomService) Query

func (this *ChatroomService) Query(args []string) bool

func (*ChatroomService) Quit

func (this *ChatroomService) Quit(args []string) bool

type ClientConf

type ClientConf struct {
	Tag           string
	ConnType      string // Connection Type: "tcp" or "websocket"
	ServerAddr    string // Server address
	CenterAddr    string // Center address
	AppID         uint32 // ApplicationID
	ClientVer     int    // ClientVersion
	ProtoVer      int    // ProtocolVersion
	DefaultKey    string // Default Key
	Heartbeat     int    // Heartbeat interval (unit second)
	SendHeartbeat int    // Send heart beat or not, if value is 0, don't send, otherwise send.
	AutoLogin     int    // autologin when init login, if the value is not 0
}

type GroupService

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

func (*GroupService) GetMsg

func (gs *GroupService) GetMsg(groupid string, startid uint64, offset int32) bool

func (*GroupService) GetMsgBatch

func (gs *GroupService) GetMsgBatch(ids []int64) bool

func (*GroupService) HandleGetMessage

func (gs *GroupService) HandleGetMessage(msg *UserMessage) bool

func (*GroupService) HandleServiceMessage

func (gs *GroupService) HandleServiceMessage(data []byte, sn uint64, source int) bool

func (*GroupService) Sync

func (gs *GroupService) Sync() bool

type MessageSlot

type MessageSlot struct {
	InfoType string
	LatestID int64
}

type ServiceHandler

type ServiceHandler interface {
	HandleServiceMessage(data []byte, sn uint64, source int) bool
	HandleGetMessage(msg *UserMessage) bool
}

type Stream

type Stream interface {
	Close()
	Read([]byte) (int, error)
	Write([]byte) (int, error)
	SetReadDeadline(t time.Time) error
	SetWriteDeadline(t time.Time) error
}

type TcpStream

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

func NewTcpStream

func NewTcpStream(addr string, timeout time.Duration) (*TcpStream, error)

func (*TcpStream) Close

func (this *TcpStream) Close()

func (*TcpStream) Read

func (this *TcpStream) Read(data []byte) (int, error)

func (*TcpStream) SetReadDeadline

func (this *TcpStream) SetReadDeadline(t time.Time) error

func (*TcpStream) SetWriteDeadline

func (this *TcpStream) SetWriteDeadline(t time.Time) error

func (*TcpStream) Write

func (this *TcpStream) Write(data []byte) (int, error)

type UserConnection

type UserConnection struct {
	CmdChan chan []string // export
	// contains filtered or unexported fields
}

func NewUserConnection

func NewUserConnection(c *ClientConf, a *AccountInfo, v bool) *UserConnection

func (*UserConnection) RequestService

func (c *UserConnection) RequestService(serviceID int, data []byte) bool

func (*UserConnection) Start

func (c *UserConnection) Start(ch chan string)

type UserMessage

type UserMessage struct {
	ID       uint64
	Content  []byte
	InfoType string
	MsgType  uint32
	Sn       uint64
	Valid    uint32
}

type WebSocketStream

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

func NewWebSocketStream

func NewWebSocketStream(addr string, timeout time.Duration) (*WebSocketStream, error)

func (*WebSocketStream) Close

func (ws *WebSocketStream) Close()

func (*WebSocketStream) Read

func (ws *WebSocketStream) Read(data []byte) (n int, err error)

func (*WebSocketStream) SetReadDeadline

func (ws *WebSocketStream) SetReadDeadline(t time.Time) error

func (*WebSocketStream) SetWriteDeadline

func (ws *WebSocketStream) SetWriteDeadline(t time.Time) error

func (*WebSocketStream) Write

func (ws *WebSocketStream) Write(data []byte) (int, error)

Jump to

Keyboard shortcuts

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