Esempio n. 1
0
func main() {
	flag.Parse()
	if *runMode == "server" {

		s := turnpike.NewServer(false)

		http.Handle("/ws", s.Handler)
		err := http.ListenAndServe(":8080", nil)
		if err != nil {
			panic("ListenAndServe: " + err.Error())
		}

	} else if *runMode == "client" {
		c := turnpike.NewClient()
		err := c.Connect("ws://127.0.0.1:8080/ws", "http://localhost/")
		if err != nil {
			panic("Error connecting:" + err.Error())
		}

		c.Subscribe("event:test", testHandler)

		for {
			c.Publish("event:test", "test")
			<-time.After(time.Second)
		}
	} else {
		fmt.Printf("runMode must be one of server or client, you passed %s", runMode)
	}
}
Esempio n. 2
0
func main() {
	flag.Parse()
	if *runMode == "server" {
		s := turnpike.NewServer(false)
		s.RegisterRPC("rpc:test", handleTest)

		http.Handle("/ws", s.Handler)
		err := http.ListenAndServe(":8080", nil)
		if err != nil {
			panic("ListenAndServe: " + err.Error())
		}

	} else if *runMode == "client" {
		c := turnpike.NewClient()
		err := c.Connect("ws://127.0.0.1:8080/ws", "http://localhost/")
		if err != nil {
			panic("Error connecting:" + err.Error())
		}

		resultCh := c.Call("rpc:test")
		result := <-resultCh
		fmt.Printf("Call result is: %s\n", result.Result)
	} else {
		fmt.Printf("runMode must be one of server or client, you passed %s", runMode)
	}
}
Esempio n. 3
0
func main() {
	s := turnpike.NewServer(false)
	http.Handle("/", websocket.Handler(s.HandleWebsocket))
	fmt.Println("Listening on port 8080")
	if err := http.ListenAndServe(":8080", nil); err != nil {
		log.Fatal("ListenAndServe:", err)
	}
}
Esempio n. 4
0
func ExampleServer_NewServer() {
	s := turnpike.NewServer(false)

	http.Handle("/ws", s.Handler)
	err := http.ListenAndServe(":8080", nil)
	if err != nil {
		panic("ListenAndServe: " + err.Error())
	}
}
Esempio n. 5
0
func main() {
	s := turnpike.NewServer(false)
	http.Handle("/ws", s.Handler)
	http.Handle("/", http.FileServer(http.Dir("web")))

	fmt.Println("Listening on port 8080")
	if err := http.ListenAndServe(":8080", nil); err != nil {
		log.Fatal("ListenAndServe:", err)
	}
}