gsi
github.com/nkovacs/go-socket.io
go get github.com/nkovacs/go-socket.io
gsi

github.com/nkovacs/go-socket.io

socket.io library for golang, a realtime application framework.

by Nikola Kovacs

v0.0.0-20160407114850-e507d8cf976e (see all)License:BSD-3-Clause
go get github.com/nkovacs/go-socket.io
Readme

socket.io

GoDoc Build Status

go-socket.io is an implementation of socket.io in golang, which is a realtime application framework.

It is compatible with latest implementation of socket.io in node.js, and supports room and namespace.

  • for compatability with socket.io 0.9.x, please use branch 0.9.x *

Install

Install the package with:

go get github.com/nkovacs/go-socket.io

Import it with:

import "github.com/nkovacs/go-socket.io"

and use socketio as the package name inside the code.

Example

Please check the example folder for details.

package main

import (
    "log"
    "net/http"

    "github.com/nkovacs/go-socket.io"
)

func main() {
    server, err := socketio.NewServer(nil)
    if err != nil {
        log.Fatal(err)
    }
    server.On("connection", func(so socketio.Socket) {
        log.Println("on connection")
        so.Join("chat")
        so.On("chat message", func(msg string) {
            log.Println("emit:", so.Emit("chat message", msg))
            so.BroadcastTo("chat", "chat message", msg)
        })
        so.On("disconnection", func() {
            log.Println("on disconnect")
        })
    })
    server.On("error", func(so socketio.Socket, err error) {
        log.Println("error:", err)
    })

    http.Handle("/socket.io/", server)
    http.Handle("/", http.FileServer(http.Dir("./asset")))
    log.Println("Serving at localhost:5000...")
    log.Fatal(http.ListenAndServe(":5000", nil))
}

License

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

GitHub Stars

12

LAST COMMIT

6yrs ago

MAINTAINERS

0

CONTRIBUTORS

29

OPEN ISSUES

0

OPEN PRs

0
VersionTagPublished
v0.0.0-20160407114850-e507d8cf976e
3yrs ago
No alternatives found
No tutorials found
Add a tutorial