gosocketio

package module
v0.0.0-...-299b620 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2021 License: GPL-3.0 Imports: 16 Imported by: 0

README

go-socket.io

介绍

{以下是 Gitee 平台说明,您可以替换此简介 Gitee 是 OSCHINA 推出的基于 Git 的代码托管平台(同时支持 SVN)。专为开发者提供稳定、高效、安全的云端软件开发协作平台 无论是个人、团队、或是企业,都能够用 Gitee 实现代码托管、项目管理、协作开发。企业项目请看 https://gitee.com/enterprises}

软件架构

软件架构说明

安装教程
  1. xxxx
  2. xxxx
  3. xxxx
使用说明
  1. xxxx
  2. xxxx
  3. xxxx
参与贡献
  1. Fork 本仓库
  2. 新建 Feat_xxx 分支
  3. 提交代码
  4. 新建 Pull Request
特技
  1. 使用 Readme_XXX.md 来支持不同的语言,例如 Readme_en.md, Readme_zh.md
  2. Gitee 官方博客 blog.gitee.com
  3. 你可以 https://gitee.com/explore 这个地址来了解 Gitee 上的优秀开源项目
  4. GVP 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
  5. Gitee 官方提供的使用手册 https://gitee.com/help
  6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 https://gitee.com/gitee-stars/

Documentation

Index

Constants

View Source
const (
	OnConnection    = "connection"
	OnDisconnection = "disconnection"
	OnError         = "error"
)

Variables

View Source
var (
	ErrorSendTimeout     = errors.New("timeout")
	ErrorSocketOverflood = errors.New("socket overflood")
)
View Source
var (
	ErrorHandlerIsNotFunc   = errors.New("f is not a function")
	ErrorHandlerHasNot2Args = errors.New("f should have 1 or 2 arguments")
	ErrorHandlerWrongResult = errors.New("f should return no more than one value")
)
View Source
var (
	ErrorServerNotSet       = errors.New("server was not set")
	ErrorConnectionNotFound = errors.New("connection not found")
)
View Source
var (
	ErrorAckWaiterNotFound = errors.New("ack waiter not found")
)

Functions

func AddrPolling

func AddrPolling(host string, port int, socketioPollingURL string, secure bool) string

AddrPolling returns an url for socket.io connection for polling transport

func AddrWebsocket

func AddrWebsocket(host string, port int, socketioWebsocketURL string, secure bool) string

AddrWebsocket returns an url for socket.io connection for websocket transport

func CountOverfloodingChannels

func CountOverfloodingChannels() int

CountOverfloodingChannels returns an amount of overflooding channels

Types

type Channel

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

Channel represents socket.io connection

func (*Channel) Ack

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

Ack a synchronous event with the given name and payload and wait for/receive the response

func (*Channel) Amount

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

Amount returns an amount of channels joined to the given room, using channel

func (*Channel) BroadcastTo

func (c *Channel) BroadcastTo(room, name string, payload interface{})

BroadcastTo the the given room an event with given name and payload, using channel

func (*Channel) Close

func (c *Channel) Close() error

Close the client (Channel) connection

func (*Channel) Emit

func (c *Channel) Emit(name string, payload interface{}) error

Emit an asynchronous event with the given name and payload

func (*Channel) IP

func (c *Channel) IP() string

IP returns an IP of the socket client

func (*Channel) Id

func (c *Channel) Id() string

Id returns an ID of the current socket connection

func (*Channel) IsAlive

func (c *Channel) IsAlive() bool

IsAlive checks that Channel is still alive

func (*Channel) Join

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

Join this channel to the given room

func (*Channel) Leave

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

Leave the given room (remove channel from it)

func (*Channel) List

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

List returns a list of channels joined to the given room, using channel

func (*Channel) RequestHeader

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

RequestHeader returns a connection request connectionHeader

type Client

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

Client represents socket.io client

func Dial

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

Dial connects to server and initializes socket.io protocol The correct ws protocol addr example: ws://myserver.com/socket.io/?EIO=3&transport=websocket

func (*Client) Close

func (c *Client) Close()

Close client connection

func (Client) On

func (e Client) On(name string, f interface{}) error

On registers message processing function and binds it to the given event name

type Server

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

Server represents a socket.io server instance

func NewServer

func NewServer() *Server

NewServer creates 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) BroadcastTo

func (s *Server) BroadcastTo(room, name string, payload interface{})

BroadcastTo the the given room an handler with payload, using server

func (*Server) BroadcastToAll

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

Broadcast to all clients

func (*Server) CountChannels

func (s *Server) CountChannels() int

CountChannels returns an amount of connected channels

func (*Server) CountRooms

func (s *Server) CountRooms() int

CountRooms returns an amount of rooms with at least one joined channel

func (*Server) GetChannel

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

GetChannel by it's sid

func (*Server) List

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

List returns a list of channels joined to the given room, using server

func (Server) On

func (e Server) On(name string, f interface{}) error

On registers message processing function and binds it to the given event name

func (*Server) ServeHTTP

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

ServeHTTP makes Server to implement http.Handler

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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