Пример #1
0
func main() {
	log.Println("server started...")

	sockjs.Install("/sockjs/echo", sockEchoHandler, sockjs.DefaultConfig)
	sockjs.Install("/sockjs/ping", sockPingHandler, sockjs.DefaultConfig)
	sockjs.Install("/sockjs/startstop", sockStartStopHandler, sockjs.DefaultConfig)
	sockjs.Install("/sockjs/sine", sockSineHandler, sockjs.DefaultConfig)

	http.Handle("/static/", http.FileServer(http.Dir(folder_static)))
	http.HandleFunc("/", pageHandler)

	err := http.ListenAndServe(":8080", nil)
	log.Fatal(err)
}
Пример #2
0
func main() {
	log.Println("server started")

	sockjs.Install("/echo", SockJSHandler, sockjs.DefaultConfig)
	http.Handle("/", http.FileServer(http.Dir("./www")))
	err := http.ListenAndServe(":8080", nil)
	log.Fatal(err)
}
Пример #3
0
func main() {
	log.Println("server started")

	cfg_ws_off := sockjs.DefaultConfig
	cfg_ws_off.Websocket = false

	cfg_4096_limit := sockjs.DefaultConfig
	cfg_4096_limit.ResponseLimit = 4096
	cfg_4096_limit.DecodeFrames = true

	cfg_cookie_needed := cfg_4096_limit
	cfg_cookie_needed.CookieNeeded = true

	sockjs.Install("/echo", EchoHandler, cfg_4096_limit)
	sockjs.Install("/close", CloseHandler, sockjs.DefaultConfig)
	sockjs.Install("/cookie_needed_echo", EchoHandler, cfg_cookie_needed)
	sockjs.Install("/disabled_websocket_echo", EchoHandler, cfg_ws_off)

	err := http.ListenAndServe(":8081", new(NoRedirectServer))
	log.Fatal(err)
}
Пример #4
0
func ExampleInstall() {
	// Echo Handler
	var handler = func(c sockjs.Conn) {
		for {
			msg, err := c.ReadMessage()
			if err == sockjs.ErrConnectionClosed {
				return
			}
			c.WriteMessage(msg)
		}
	}
	// install echo sockjs in default http handler
	sockjs.Install("/echo", handler, sockjs.DefaultConfig)
	http.ListenAndServe(":8080", nil)
}
Пример #5
0
func (self *SockjsDispatcherTransport) Listen(messageChannel chan dispatcher_message.Message, clients *dispatcher_client.Clients) {
	sockjs.Install("/sockjs", func(session sockjs.Conn) {
		client := SockjsClient{&session}
		c := dispatcher_client.Client(client)
		err := self.auth.Authenticate(&c)
		if err == nil {
			log.Println("Dispatcher client authentication passed: %s", client)
			clients.Add(client)
			self.ConnectionHandler(session)
		} else {
			log.Println("Dispatcher client authentication failed: %s", err)
		}
	}, sockjs.DefaultConfig)
	http.Handle("/", http.FileServer(http.Dir("./www")))
	http_err := http.ListenAndServe(":8080", nil)
	log.Fatal(http_err)
}