m2mprotocol

package
v0.0.0-...-af70fd6 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2015 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Protocol layer used for client and server connection handling.

Index

Constants

View Source
const (
	MODE_CLIENT = iota // Client mode
	MODE_SERVER = iota // Server mode
)
View Source
const (
	PROTO_IDENT_REQUEST  = 0x01 // Identification request
	PROTO_IDENT_RESPONSE = 0X01 // Identification response
	PROTO_CLIENT_PING    = 0x02 // Ping request (client to server)
	PROTO_SERVER_PONG    = 0x02 // Pong request (server to client)
	PROTO_SERVER_PING    = 0x03 // Ping request (server to client)
	PROTO_CLIENT_PONG    = 0x03 // Pong request (client to server)
	PROTO_DATA_SIMPLE_1B = 0x21
	PROTO_DATA_SIMPLE_2B = 0x41
	PROTO_DATA_SIMPLE_4B = 0x61
	PROTO_DATA_ARRAY_1B  = 0x22
	PROTO_DATA_ARRAY_2B  = 0x42
	PROTO_DATA_ARRAY_4B  = 0x62

	PROTO_MAX_SIZE_1B = 254     // 255 - 1 (for channel)
	PROTO_MAX_SIZE_2B = 65534   // 64K - 1 (for channel)
	PROTO_MAX_SIZE_4B = 1048576 // 1MB (we don't want to send more than 1MB at this stage)
)
View Source
const (
	BUFFER_SIZE = 1024 // Buffer size
)

Variables

This section is empty.

Functions

func UvarintBE

func UvarintBE(data []byte) (int, error)

Types

type EventDisconnected

type EventDisconnected struct {
	Error error
}

Disconnection

type MessageDataArray

type MessageDataArray struct {
	Channel string
	Data    [][]byte
}

Array of data message

func NewMessageDataArray

func NewMessageDataArray(channel string) *MessageDataArray

func (*MessageDataArray) Add

func (msg *MessageDataArray) Add(data []byte)

func (*MessageDataArray) AddString

func (msg *MessageDataArray) AddString(data string)

type MessageDataSimple

type MessageDataSimple struct {
	Channel string
	Data    []byte
}

Simple message

type MessageIdentRequest

type MessageIdentRequest struct {
	Ident string
}

type MessageIdentResponse

type MessageIdentResponse struct {
	Ok bool
}

type MessagePingRequest

type MessagePingRequest struct {
	Data byte
}

Ping request

type MessagePingResponse

type MessagePingResponse struct {
	Data byte
}

Ping response

type ProtoHandler

type ProtoHandler struct {
	Conn net.Conn

	// Logging is done on a connection basis to be to focus on some connections
	LogLevel int
	// contains filtered or unexported fields
}

func NewProtoHandlerClient

func NewProtoHandlerClient(c net.Conn) (pt *ProtoHandler)

Create a new protocol handler in client mode This is used to initiate a connection.

func NewProtoHandlerServer

func NewProtoHandlerServer(c net.Conn) (pt *ProtoHandler)

Create a new protocol handler in server mode This is used to handle an incoming connection.

func (*ProtoHandler) Recv

func (pt *ProtoHandler) Recv() interface{}

func (*ProtoHandler) Send

func (pt *ProtoHandler) Send(msg interface{}) error

func (*ProtoHandler) String

func (pt *ProtoHandler) String() string

Jump to

Keyboard shortcuts

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