gosocketio

package module
v0.0.0-...-7a641e5 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2018 License: GPL-3.0, MIT Imports: 16 Imported by: 0

README

golang socket.io

自己工程用的,可以收BinaryEvent,不清楚的不要用。

For my own project,it can receive Binary Event,if you Don't know how to use, don't download it!!!

可以支持自己测试中的json和pb协议了。

Roadmap
  1. Tests
  2. Travis CI
  3. http longpoll transport
  4. pure http (short-timed queries) transport
  5. binary format
Licence

Double licensed under GPL3 and MIT so you can use whichever you please.

Documentation

Index

Constants

View Source
const (
	OnConnection    = "connection"
	OnDisconnection = "disconnection"
	OnError         = "error"
)
View Source
const (
	HeaderForward = "X-Forwarded-For"
)

Variables

View Source
var (
	ErrorCallerNotFunc     = errors.New("f is not function")
	ErrorCallerNot2Args    = errors.New("f should have 1 or 2 args")
	ErrorCallerMaxOneValue = errors.New("f should return not more than one value")
)
View Source
var (
	ErrorSendTimeout     = errors.New("Timeout")
	ErrorSocketOverflood = errors.New("Socket overflood")
)
View Source
var (
	ErrorServerNotSet       = errors.New("Server not set")
	ErrorConnectionNotFound = errors.New("Connection not found")
)
View Source
var (
	ErrorWaiterNotFound = errors.New("Waiter not found")
)
View Source
var (
	ErrorWrongHeader = errors.New("Wrong header")
)

Functions

func AmountOfOverflooded

func AmountOfOverflooded() int64

func Dial

func Dial(url string, tr transport.Transport, c *Client) error

* connect to host and initialise socket.io protocol

The correct ws protocol url example: ws://myserver.com/socket.io/?EIO=3&transport=websocket

You can use GetUrlByHost for generating correct url

func GetUrl

func GetUrl(host string, port int, secure bool) string

* Get ws/wss url by host and port

Types

type Channel

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

* socket.io connection handler

use IsAlive to check that handler is still working use Dial to connect to websocket use In and Out channels for message exchange Close message means channel is closed ping is automatic

func (*Channel) Ack

func (c *Channel) Ack(method string, args interface{}, timeout time.Duration) (string, error)

* Create ack packet based on given data and send it and receive response

func (*Channel) Amount

func (c *Channel) Amount(room string) int

* Get amount of channels, joined to given room, using channel

func (*Channel) BroadcastTo

func (c *Channel) BroadcastTo(room, method string, args interface{})

func (*Channel) Close

func (c *Channel) Close()

* Close current channel

func (*Channel) Emit

func (c *Channel) Emit(method string, args interface{}) error

* Create packet based on given data and send it

func (*Channel) EmitData

func (c *Channel) EmitData(method string, data []byte, args interface{}) error

* Create packet based on given data and send it

func (*Channel) GetConnect

func (c *Channel) GetConnect() transport.Connection

func (*Channel) Id

func (c *Channel) Id() string

* Get id of current socket connection

func (*Channel) Ip

func (c *Channel) Ip() string

* Get ip of socket client

func (*Channel) IsAlive

func (c *Channel) IsAlive() bool

* Checks that Channel is still alive

func (*Channel) Join

func (c *Channel) Join(room string) error

* Join this channel to given room

func (*Channel) Leave

func (c *Channel) Leave(room string) error

* Remove this channel from given room

func (*Channel) List

func (c *Channel) List(room string) []*Channel

* Get list of channels, joined to given room, using channel

func (*Channel) RequestHeader

func (c *Channel) RequestHeader() http.Header

* Get request header of this connection

type Client

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

* Socket.io client representation

func InitConnect

func InitConnect() *Client

func (*Client) Close

func (c *Client) Close()

* Close client connection

func (*Client) On

func (m *Client) On(method string, f interface{}) error

* Add message processing function, and bind it to given method

type Header struct {
	Sid          string   `json:"sid"`
	Upgrades     []string `json:"upgrades"`
	PingInterval int      `json:"pingInterval"`
	PingTimeout  int      `json:"pingTimeout"`
}

* engine.io header to send or receive

type Server

type Server struct {
	http.Handler
	// contains filtered or unexported fields
}

* socket.io server instance

func NewServer

func NewServer(tr transport.Transport) *Server

* Create new socket.io server

func (*Server) Amount

func (s *Server) Amount(room string) int

* Get amount of channels, joined to given room, using server

func (*Server) AmountOfRooms

func (s *Server) AmountOfRooms() int64

* Get amount of rooms with at least one channel(or sid) joined

func (*Server) AmountOfSids

func (s *Server) AmountOfSids() int64

* Get amount of current connected sids

func (*Server) BroadcastTo

func (s *Server) BroadcastTo(room, method string, args interface{})

* Broadcast message to all room channels

func (*Server) BroadcastToAll

func (s *Server) BroadcastToAll(method string, args interface{})

* Broadcast to all clients

func (*Server) GetChannel

func (s *Server) GetChannel(sid string) (*Channel, error)

* Get channel by it's sid

func (*Server) List

func (s *Server) List(room string) []*Channel

* Get list of channels, joined to given room, using server

func (*Server) On

func (m *Server) On(method string, f interface{}) error

* Add message processing function, and bind it to given method

func (*Server) SendOpenSequence

func (s *Server) SendOpenSequence(c *Channel)

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

* implements ServeHTTP function from http.Handler

func (*Server) SetupEventLoop

func (s *Server) SetupEventLoop(conn transport.Connection, remoteAddr string,
	requestHeader http.Header)

* Setup event loop for given connection

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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