示例#1
0
文件: dpg_test.go 项目: alLi1n/djdns
func setup_deje_env(t *testing.T) (string, string, func(), *deje.SimpleClient, deje.Client) {
	tp := turnpike.NewServer()
	router := httptest.NewServer(tp.Handler)
	deje_url := strings.Replace(router.URL, "http", "deje", 1) + "/"
	router_url, topic, err := deje.GetRouterAndTopic(deje_url)
	if err != nil {
		t.Fatal(err)
	}
	closer := func() {
		router.CloseClientConnections()
		router.Close()
	}

	clever, err := deje.Open(deje_url, nil, nil)
	if err != nil {
		t.Fatal(err)
	}

	dumb := deje.NewClient(topic)
	err = dumb.Connect(router_url)
	if err != nil {
		t.Fatal(err)
	}
	<-time.After(50 * time.Millisecond)

	return router_url, topic, closer, clever, dumb
}
示例#2
0
文件: misc_test.go 项目: alLi1n/djdns
func setupRouter() (url string, closer func()) {
	websocket_server := httptest.NewServer(turnpike.NewServer().Handler)
	closer = func() {
		websocket_server.CloseClientConnections()
		websocket_server.Close()
	}
	url = strings.Replace(websocket_server.URL, "http", "deje", 1) + "/root"
	return
}
示例#3
0
func ExampleServer_NewServer() {
	s := turnpike.NewServer()

	http.Handle("/ws", s.Handler)
	err := http.ListenAndServe(":8080", nil)
	if err != nil {
		panic("ListenAndServe: " + err.Error())
	}
}
示例#4
0
func main() {
	s := turnpike.NewServer()
	s.RegisterRPC("rpc:test", handleTest)

	http.Handle("/ws", s.Handler)
	err := http.ListenAndServe(":8080", nil)
	if err != nil {
		panic("ListenAndServe: " + err.Error())
	}
}
示例#5
0
func main() {
	s := turnpike.NewServer()
	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)
	}
}
示例#6
0
文件: server.go 项目: jcelliott/speck
func main() {
	flag.Parse()
	s := turnpike.NewServer()
	ws := websocket.Handler(s.HandleWebsocket)
	http.Handle("/ws", ws)
	http.Handle("/", http.FileServer(http.Dir("web")))

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