Exemple #1
0
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())
	conf := sockjs.NewConfig()
	pool := sockjs.NewSessionPool()
	dev := controllers.NewDevice(pool, 10)
	dev.AddReader("/dev/dp0/s02_roten/count")
	dev.AddReader("/dev/dp0/s04_slider4/updates")
	sockjshandler := sockjs.NewHandler("/socket", dev.SocketHandler, conf)

	dc := controllers.DemandController{}

	beego.Router("/", &dc)
	beego.Router("/test", &controllers.ChatController{})
	beego.RouterHandler("/socket/:info(.*)", sockjshandler)
	beego.Run()
}
Exemple #2
0
	var conf Config
	err = json.Unmarshal(blob, &conf)
	checkFatalError(err)

	return conf
}

func checkFatalError(err error) {
	if err != nil {
		log.Printf("%s\n", err)
		os.Exit(-1)
	}
}

var sockjsClients *sockjs.SessionPool = sockjs.NewSessionPool()

func dataHandler(s sockjs.Session) {
	sockjsClients.Add(s)
	defer sockjsClients.Remove(s)
	for {
		m := s.Receive()
		if m == nil {
			break
		}
	}
}

func broadcast(input chan hpfeeds.Message) {
	for msg := range input {
		sockjsClients.Broadcast(msg.Payload)
Exemple #3
0
// chat room example

package main

import (
	"fmt"
	"github.com/fzzy/sockjs-go/sockjs"
	"net/http"
	"strings"
)

var users *sockjs.SessionPool = sockjs.NewSessionPool()

func chatHandler(s sockjs.Session) {
	users.Add(s)
	defer users.Remove(s)

	for {
		m := s.Receive()
		if m == nil {
			break
		}
		fullAddr := s.Info().RemoteAddr
		addr := fullAddr[:strings.LastIndex(fullAddr, ":")]
		m = []byte(fmt.Sprintf("%s: %s", addr, m))
		users.Broadcast(m)
	}
}

func indexHandler(w http.ResponseWriter, r *http.Request) {
	http.ServeFile(w, r, "./static/index.html")
Exemple #4
0
func init() {
	Users = sockjs.NewSessionPool()
	Conf = sockjs.NewConfig()
	SockjsHandler = sockjs.NewHandler("/chat", ChatHandler, Conf)
}