Пример #1
0
func main() {
	conf := sockjs.NewConfig()
	sockjshandler := sockjs.NewHandler("/chat", chatHandler, conf)
	beego.Router("/", &MainController{})
	beego.RouterHandler("/chat/{<info(.*)>}", sockjshandler)
	beego.Run()
}
Пример #2
0
func Example() {
	// Handlers for two echo servers and a file server.
	conf := sockjs.NewConfig()
	dwsconf := sockjs.NewConfig()
	dwsconf.Websocket = false

	mux := sockjs.NewServeMux(http.DefaultServeMux)
	mux.Handle("/echo", echoHandler, conf)
	mux.Handle("/disabled_websocket_echo", echoHandler, dwsconf)
	http.Handle("/static", http.FileServer(http.Dir("./static")))

	err := http.ListenAndServe(":8081", mux)
	if err != nil {
		fmt.Println(err)
	}
}
Пример #3
0
func ExampleNewHandler() {
	// Handle only SockJS requests prefixed with "/echo".
	h := sockjs.NewHandler("/echo", echoHandler, sockjs.NewConfig())
	err := http.ListenAndServe(":8081", h)
	if err != nil {
		fmt.Println(err)
	}
}
Пример #4
0
func main() {
	static := http.FileServer(http.Dir("static/"))
	s := sockjs.NewServeMux(static)
	s.Handle("/api", connHandler, sockjs.NewConfig())

	println("starting on 7171...")
	err := http.ListenAndServe(":7171", s)
	if err != nil {
		log.Fatal(err)
	}
}
Пример #5
0
func main() {
	mux := sockjs.NewServeMux(http.DefaultServeMux)
	conf := sockjs.NewConfig()
	http.Handle("/static", http.FileServer(http.Dir("./static")))
	http.HandleFunc("/", indexHandler)
	mux.Handle("/chat", chatHandler, conf)

	err := http.ListenAndServe(":8081", mux)
	if err != nil {
		fmt.Println(err)
	}
}
Пример #6
0
func main() {
	mux := sockjs.NewServeMux(http.DefaultServeMux)
	conf := sockjs.NewConfig()
	conf.ResponseLimit = 4096
	dwsconf := sockjs.NewConfig()
	dwsconf.Websocket = false
	cookieconf := sockjs.NewConfig()
	cookieconf.Jsessionid = true

	http.Handle("/static", http.FileServer(http.Dir("./static")))
	mux.Handle("/echo", echoHandler, conf)
	mux.Handle("/disabled_websocket_echo", echoHandler, dwsconf)
	mux.Handle("/cookie_needed_echo", echoHandler, cookieconf)
	mux.Handle("/close",
		func(s sockjs.Session) { s.End() },
		conf)
	err := http.ListenAndServe(":8081", mux)
	if err != nil {
		fmt.Println(err)
	}
}
Пример #7
0
func _startWebsocketServer() {

	wsCfg := &wsConfig{}
	framework.Config.ReadInto("websocket", &wsCfg)

	log.Println("Starting websocket server on port", wsCfg.Port)

	server := sockjs.NewServeMux(http.DefaultServeMux)
	conf := sockjs.NewConfig()

	server.Handle("/ws", wssockjs.HandleSockjsSession, conf)

	http.ListenAndServe(":"+wsCfg.Port, server)

}
Пример #8
0
func main() {
	config := readConfig()

	http.Handle("/", http.FileServer(http.Dir(dirname()+"/"+staticDir+"/")))
	sockjsMux := sockjs.NewServeMux(http.DefaultServeMux)
	sockjsConf := sockjs.NewConfig()
	sockjsMux.Handle("/data", dataHandler, sockjsConf)

	geolocEvents := make(chan hpfeeds.Message)
	go hpfeedsConnect(config, geolocEvents)
	go broadcast(geolocEvents)

	log.Printf("Binding Honeymap webserver to %s...", bind)
	err := http.ListenAndServe(bind, sockjsMux)
	checkFatalError(err)
}
Пример #9
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()
}
Пример #10
0
func main() {
	http.Handle("/", http.FileServer(http.Dir("../../client/")))
	sockjsMux := sockjs.NewServeMux(http.DefaultServeMux)
	sockjsConf := sockjs.NewConfig()
	sockjsMux.Handle("/data", dataHandler, sockjsConf)

	go func() {
		for {
			lat := rand.Float32()*180 - 90
			lng := rand.Float32()*360 - 180
			sockjsClients.Broadcast([]byte(fmt.Sprintf("{ \"latitude\": %f, \"longitude\": %f }", lat, lng)))
			time.Sleep(100 * time.Millisecond)
		}
	}()

	log.Printf("Binding Honeymap webserver to %s...", bind)
	http.ListenAndServe(bind, sockjsMux)
}
Пример #11
0
func main() {

	http.Handle("/", http.FileServer(http.Dir(dirname()+"/"+staticDir+"/")))
	sockjsMux := sockjs.NewServeMux(http.DefaultServeMux)
	sockjsConf := sockjs.NewConfig()
	sockjsMux.Handle("/data", dataHandler, sockjsConf)
	go events_listner()
	go func() {
		for {
			var msg = <-message
			//s:=fmt.Sprintf("{\"latitude\": 32.0617, \"type\": \"blacklist\", \"longitude\": 118.7778,\"countrycode\":\"PT\", \"city\":\"Lisboa\"}")
			sockjsClients.Broadcast([]byte(msg))
		}
	}()
	log.Printf("Binding Honeymap webserver to %s...", bind)
	err := http.ListenAndServe(bind, sockjsMux)
	checkFatalError(err)
}
Пример #12
0
func init() {
	Users = sockjs.NewSessionPool()
	Conf = sockjs.NewConfig()
	SockjsHandler = sockjs.NewHandler("/chat", ChatHandler, Conf)
}