package main import ( "log" "net/http" "time" gosocketio "forge.cadoles.com/Pyxis/golang-socketio" "forge.cadoles.com/Pyxis/golang-socketio/transport" ) type Channel struct { Channel string `json:"channel"` } type Message struct { Id int `json:"id"` Channel string `json:"channel"` Text string `json:"text"` } func main() { server := gosocketio.NewServer(transport.GetDefaultWebsocketTransport()) server.On(gosocketio.OnConnection, func(c *gosocketio.Channel) { log.Println("Connected") c.Emit("/message", Message{10, "main", "using emit"}) c.Join("test") c.BroadcastTo("test", "/message", Message{10, "main", "using broadcast"}) }) server.On(gosocketio.OnDisconnection, func(c *gosocketio.Channel) { log.Println("Disconnected") }) server.On("/join", func(c *gosocketio.Channel, channel Channel) string { time.Sleep(2 * time.Second) log.Println("Client joined to ", channel.Channel) return "joined to " + channel.Channel }) serveMux := http.NewServeMux() serveMux.Handle("/socket.io/", server) log.Println("Starting server...") log.Panic(http.ListenAndServe(":3811", serveMux)) }