socketio

package module
v1.2.6 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2024 License: MIT Imports: 17 Imported by: 0

README

Socket.IO

Socket.IO 是一个面向实时 web 应用的 实时通讯库。它使得服务器和客户端之间实时双向的通信成为可能。他有两个部分:在浏览器中运行的客户端库,和一个面向Node.js的服务端库。两者有着几乎一样的API。像Node.js一样,它也是事件驱动的.

Socket.IO 主要使用WebSocket协议。但是如果需要的话,Socket.io可以回退到几种其它方法,例如Adobe Flash Sockets,JSONP拉取,或是传统的AJAX拉取,[4]并且在同时提供完全相同的接口。尽管它可以被用作WebSocket的包装库,它还是提供了许多其它功能,比如广播至多个套接字,存储与不同客户有关的数据,和异步IO操作。

参考资料 (Reference)

Documentation

Index

Constants

View Source
const (
	KindSocketIo transport.Kind = "socket.io"
)

Variables

This section is empty.

Functions

func SetOperation

func SetOperation(ctx context.Context, op string)

SetOperation sets the transport operation.

Types

type Server

type Server struct {
	*socketIo.Server
	// contains filtered or unexported fields
}

func NewServer

func NewServer(opts ...ServerOption) *Server

func (*Server) Endpoint

func (s *Server) Endpoint() (*url.URL, error)

func (*Server) Name

func (s *Server) Name() string

func (*Server) RegisterConnectHandler

func (s *Server) RegisterConnectHandler(namespace string, f func(socketIo.Conn) error)

func (*Server) RegisterDisconnectHandler

func (s *Server) RegisterDisconnectHandler(namespace string, f func(socketIo.Conn, string))

func (*Server) RegisterErrorHandler

func (s *Server) RegisterErrorHandler(namespace string, f func(socketIo.Conn, error))

func (*Server) RegisterEventHandler

func (s *Server) RegisterEventHandler(namespace, event string, f interface{})

func (*Server) Start

func (s *Server) Start(_ context.Context) error

func (*Server) Stop

func (s *Server) Stop(_ context.Context) error

type ServerOption

type ServerOption func(o *Server)

func WithAddress

func WithAddress(addr string) ServerOption

func WithCodec

func WithCodec(c string) ServerOption

func WithConnectHandler

func WithConnectHandler(namespace string, f func(socketIo.Conn) error) ServerOption

func WithDisconnectHandler

func WithDisconnectHandler(namespace string, f func(socketIo.Conn, string)) ServerOption

func WithErrorHandler

func WithErrorHandler(namespace string, f func(socketIo.Conn, error)) ServerOption

func WithEventHandler

func WithEventHandler(namespace, event string, f interface{}) ServerOption

func WithNetwork

func WithNetwork(network string) ServerOption

func WithPath

func WithPath(path string) ServerOption

func WithTLSConfig

func WithTLSConfig(c *tls.Config) ServerOption

type Transport

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

Transport is a websocket transport.

func (*Transport) Endpoint

func (tr *Transport) Endpoint() string

Endpoint returns the transport endpoint.

func (*Transport) Kind

func (tr *Transport) Kind() transport.Kind

Kind returns the transport kind.

func (*Transport) Operation

func (tr *Transport) Operation() string

Operation returns the transport operation.

func (*Transport) PathTemplate

func (tr *Transport) PathTemplate() string

PathTemplate returns the http path template.

func (*Transport) ReplyHeader

func (tr *Transport) ReplyHeader() transport.Header

ReplyHeader returns the reply header.

func (*Transport) Request

func (tr *Transport) Request() *http.Request

Request returns the HTTP request.

func (*Transport) RequestHeader

func (tr *Transport) RequestHeader() transport.Header

RequestHeader returns the request header.

type Transporter

type Transporter interface {
	transport.Transporter
	Request() *http.Request
	PathTemplate() string
}

Jump to

Keyboard shortcuts

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