https://github.com/taigrr/socketio
https://github.com/taigrr/socketio
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/taigrr/socketio
- Owner: taigrr
- License: other
- Created: 2023-04-27T22:07:16.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2023-07-10T23:08:09.000Z (almost 3 years ago)
- Last Synced: 2025-03-06T14:31:08.238Z (over 1 year ago)
- Language: JavaScript
- Size: 971 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# socketio
[](https://pkg.go.dev/github.com/taigrr/socketio)
A Go (golang) implementation of [socket.io](https://socket.io), compatible with socket.io version 2.3.0.
Supports rooms, namespaces, and real-time bidirectional browser-server communication.
Originally forked from [googollee/go-socket.io](https://github.com/googollee/go-socket.io) with
defect fixes, import cleanup, and dependency modernization.
## Install
```bash
go get github.com/taigrr/socketio
```
## Example
See the [examples/chat](./examples/chat) directory for a full working chat server.
```go
package main
import (
"fmt"
"log"
"net/http"
"github.com/taigrr/socketio"
)
func main() {
server, err := socketio.NewServer(nil)
if err != nil {
log.Fatal(err)
}
server.On("connection", func(so socketio.Socket) {
fmt.Println("a user connected")
so.Join("chat")
so.On("chat message", func(msg string) {
fmt.Println("chat message:", msg)
so.BroadcastTo("chat", "chat message", msg)
})
so.On("disconnect", func() {
fmt.Println("user disconnected")
})
})
server.On("error", func(so socketio.Socket, err error) {
fmt.Printf("error: %s\n", err)
})
http.Handle("/socket.io/", server)
http.Handle("/", http.FileServer(http.Dir("./asset")))
fmt.Println("serving on :9000")
log.Fatal(http.ListenAndServe(":9000", nil))
}
```
## License
3-clause BSD — see [LICENSE](./LICENSE) for details.