package module
Version: v1.6.1 Latest Latest

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

Go to latest
Published: Sep 1, 2021 License: BSD-3-Clause Imports: 15 Imported by: 325


GoDoc Build Status Go Report Card is library an implementation of Socket.IO in Golang, which is a realtime application framework.

Current this library supports 1.4 version of the Socket.IO client. It supports room, namespaces and broadcast at now.

Help wanted This project is looking for contributors to help fix bugs and implement new features. Please check Issue 192. All help is much appreciated.



Install the package with:

go get

Import it with:

import ""

and use socketio as the package name inside the code.


Please check more examples into folder in project for details. Examples


It is some popular questions about this repository:

  • Is this library supported version 2?
    • No, but if you wanna you can help to do it. Join us in community chat Telegram
  • How to use with CORS?
  • What is minimal version Golang support for this library?
    • We required Go 1.9 or upper!
  • How to user?
    • compatibility with Socket.IO 0.9.x, please use branch 0.9.x * or tag


Telegram chat: @go_socketio


This project contains a sub-package called engineio. This used to be a separate package under

It contains the analog implementation of the original node-package. It can be used without the Please check the in engineio/.


The 3-clause BSD License - see LICENSE for more details




This section is empty.


This section is empty.


This section is empty.


type Broadcast added in v1.4.2

type Broadcast interface {
	Join(room string, connection Conn)            // Join causes the connection to join a room
	Leave(room string, connection Conn)           // Leave causes the connection to leave a room
	LeaveAll(connection Conn)                     // LeaveAll causes given connection to leave all rooms
	Clear(room string)                            // Clear causes removal of all connections from the room
	Send(room, event string, args ...interface{}) // Send will send an event with args to the room
	SendAll(event string, args ...interface{})    // SendAll will send an event with args to all the rooms
	ForEach(room string, f EachFunc)              // ForEach sends data by DataFunc, if room does not exits sends nothing
	Len(room string) int                          // Len gives number of connections in the room
	Rooms(connection Conn) []string               // Gives list of all the rooms if no connection given, else list of all the rooms the connection joined
	AllRooms() []string                           // Gives list of all the rooms the connection joined

Broadcast is the adaptor to handle broadcasts & rooms for server API

type Conn added in v1.4.1

type Conn interface {

	// ID returns session id
	ID() string
	URL() url.URL
	LocalAddr() net.Addr
	RemoteAddr() net.Addr
	RemoteHeader() http.Header

Conn is a connection in

type EachFunc added in v1.4.3

type EachFunc func(Conn)

EachFunc typed for each callback function

type Namespace added in v1.0.1

type Namespace interface {
	// Context of this connection. You can save one context for one
	// connection, and share it between all handlers. The handlers
	// is called in one goroutine, so no need to lock context if it
	// only be accessed in one connection.
	Context() interface{}
	SetContext(ctx interface{})

	Namespace() string
	Emit(eventName string, v ...interface{})

	Join(room string)
	Leave(room string)
	Rooms() []string

Namespace describes a communication channel that allows you to split the logic of your application over a single shared connection.

type RedisAdapterOptions added in v1.4.5

type RedisAdapterOptions struct {
	// deprecated. Usage Addr options
	Host string
	// deprecated. Usage Addr options
	Port    string
	Addr    string
	Prefix  string
	Network string

RedisAdapterOptions is configuration to create new adapter

type Server added in v1.0.1

type Server struct {
	// contains filtered or unexported fields

Server is a server.

func NewServer added in v1.0.1

func NewServer(opts *engineio.Options) *Server

NewServer returns a server.

func (*Server) Adapter added in v1.4.5

func (s *Server) Adapter(opts *RedisAdapterOptions) (bool, error)

Adapter sets redis broadcast adapter.

func (*Server) BroadcastToNamespace added in v1.4.5

func (s *Server) BroadcastToNamespace(namespace string, event string, args ...interface{}) bool

BroadcastToNamespace broadcasts given event & args to all the connections in the same namespace.

func (*Server) BroadcastToRoom added in v1.4.2

func (s *Server) BroadcastToRoom(namespace string, room, event string, args ...interface{}) bool

BroadcastToRoom broadcasts given event & args to all the connections in the room.

func (*Server) ClearRoom added in v1.4.2

func (s *Server) ClearRoom(namespace string, room string) bool

ClearRoom clears the room.

func (*Server) Close added in v1.4.1

func (s *Server) Close() error

Close closes server.

func (*Server) Count added in v1.0.1

func (s *Server) Count() int

Count number of connections.

func (*Server) ForEach added in v1.4.3

func (s *Server) ForEach(namespace string, room string, f EachFunc) bool

ForEach sends data by DataFunc, if room does not exits sends nothing.

func (*Server) JoinRoom added in v1.4.2

func (s *Server) JoinRoom(namespace string, room string, connection Conn) bool

JoinRoom joins given connection to the room.

func (*Server) LeaveAllRooms added in v1.4.2

func (s *Server) LeaveAllRooms(namespace string, connection Conn) bool

LeaveAllRooms leaves the given connection from all rooms.

func (*Server) LeaveRoom added in v1.4.2

func (s *Server) LeaveRoom(namespace string, room string, connection Conn) bool

LeaveRoom leaves given connection from the room.

func (*Server) OnConnect added in v1.4.1

func (s *Server) OnConnect(namespace string, f func(Conn) error)

OnConnect set a handler function f to handle open event for namespace.

func (*Server) OnDisconnect added in v1.4.1

func (s *Server) OnDisconnect(namespace string, f func(Conn, string))

OnDisconnect set a handler function f to handle disconnect event for namespace.

func (*Server) OnError added in v1.4.1

func (s *Server) OnError(namespace string, f func(Conn, error))

OnError set a handler function f to handle error for namespace.

func (*Server) OnEvent added in v1.4.1

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

OnEvent set a handler function f to handle event for namespace.

func (*Server) RoomLen added in v1.4.2

func (s *Server) RoomLen(namespace string, room string) int

RoomLen gives number of connections in the room.

func (*Server) Rooms added in v1.4.2

func (s *Server) Rooms(namespace string) []string

Rooms gives list of all the rooms.

func (*Server) Serve added in v1.4.1

func (s *Server) Serve() error

Serve serves server.

func (*Server) ServeHTTP added in v1.0.1

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

ServeHTTP dispatches the request to the handler whose pattern most closely matches the request URL.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL