A Socket.IO server and Go client with namespaces, rooms, acknowledgements,
broadcast and a Redis adapter for multi-instance deployments. Engine.IO is included as
the engineio sub-package and can be used on its own.
This module is a maintained successor of the archived googollee/go-socket.io for
socket.io-client 1.x and 2.x. Applications moving from upstream v1.4.2 or v1.7.0 should
follow the migration guide.
| Server | Socket.IO protocol | Engine.IO protocol | JavaScript client |
|---|---|---|---|
| v1 (this module, repository root) | v4 | v3 | socket.io-client 1.x and 2.x |
v2 (in development in v2/, no runtime yet) |
v5 | v4 | socket.io-client 3.x and 4.x |
The client versions and the reference server that the v1 interoperability checks use are listed in docs/PARITY.md. V1 protocol details and deviations: docs/PROTOCOL.md. The parts of the socket.io 2.x JavaScript API without a counterpart, or with a different one, are listed in docs/V1.md.
Install the module:
go get github.com/sshaplygin/go-socket.io@v1.5.0Go 1.22 or later is required.
A server whose join handler adds the socket to the lobby room, broadcasts the client's
name to that room as joined and returns the ACK:
package main
import (
"log"
"net/http"
socketio "github.com/sshaplygin/go-socket.io"
)
func main() {
if err := run(); err != nil {
panic(err)
}
}
func run() error {
server := socketio.NewServer()
defer func() { _ = server.Close() }()
root := server.Of("/")
root.OnEvent("join", func(s socketio.Conn, name string) string {
s.Join("lobby")
if err := root.To("lobby").Emit("joined", name); err != nil {
log.Print(err)
}
return "welcome, " + name // sent as the ACK when the client asks for one
})
go func() {
if err := server.Serve(); err != nil {
log.Print(err)
}
}()
http.Handle("/socket.io/", server)
return http.ListenAndServe(":8000", nil)
}A JavaScript client connected to http://localhost:8000 that calls
socket.emit("join", "Ann", ack => console.log(ack)) receives joined with Ann and the
ACK welcome, Ann.
Runnable applications and launch instructions are in _examples/. Start with the net/http server or the Go client. The directory also includes ACKs, binary events, namespaces, middleware, framework integrations, Redis and graceful shutdown.
To try Socket.IO in the browser, open the online lab.
The Go client is available in
github.com/sshaplygin/go-socket.io/client;
server and client use separate connection types and constructors.
Configuration, namespace lifecycle, rooms, deployment behind HTTP servers and load balancers, adapters and typed events: V1 usage. API reference: Socket.IO and Engine.IO.
See CONTRIBUTING.md for the PR process and CLAUDE.md for how to build and test. Report vulnerabilities privately as described in SECURITY.md.
BSD 3-Clause, see LICENSE.