Skip to content
This repository has been archived by the owner on Sep 14, 2021. It is now read-only.

jjeffcaii/socket.io

Repository files navigation

Socket.IO

Build Status

Unofficial server-side Socket.IO in Golang.

Example

package main

import (
	"fmt"
	"log"
	"net/http"

	"github.com/jjeffcaii/socket.io"
)

func main() {
	server := sio.NewBuilder().Build()
	nsp := server.Of("/")
	nsp.OnConnect(func(socket sio.Socket) {
		socket.On("news", func(msg sio.Message) {
			fmt.Println("[news]:", msg)
		})
		socket.Emit("hello", "你好,世界!")
		socket.Join("chats")
		socket.To("chats").Emit("hello", "Hello World!")
	})
	http.HandleFunc(sio.DefaultPath, server.Router())
	log.Fatalln(http.ListenAndServe(":3000", nil))
}

Documents

Please see https://godoc.org/github.com/jjeffcaii/socket.io.