示例#1
0
文件: pipe.go 项目: Yossibh/envdb
func requestGreet(s *gotalk.Sock, name string) string {
	r := ""
	if err := s.Request("greet", name, &r); err != nil {
		panic("request error: " + err.Error())
	}
	return r
}
示例#2
0
func sessionLogoutGoogle(s *gotalk.Sock, _ interface{}) error {
	c := SockClient(s)
	c.valid = false
	fmt.Printf("Google Logout: [%+v]\n", c)
	// TODO: should remove the session from the store
	s.Close()
	return nil
}
示例#3
0
func sendRequest(s *gotalk.Sock) {
	fmt.Printf("requestor: sending 'echo' request\n")
	b, err := s.BufferRequest("echo", []byte("Hello"))
	if err == gotalk.ErrTimeout {
		fmt.Printf("requestor: timed out\n")
	} else if err != nil {
		fmt.Printf("requestor: error %v\n", err.Error())
	} else {
		fmt.Printf("requestor: success: %v\n", string(b))
	}
}
示例#4
0
文件: server.go 项目: Yossibh/envdb
func onAccept(s *gotalk.Sock) {
	s.Notify("hello", "world")
	go func() {
		// Send a request & read result via JSON-encoded go values.
		greeting := GreetOut{}
		if err := s.Request("greet", GreetIn{"Rasmus"}, &greeting); err != nil {
			fmt.Printf("greet request failed: " + err.Error())
		} else {
			fmt.Printf("greet: %+v\n", greeting)
		}
	}()
}
示例#5
0
文件: server.go 项目: Yossibh/envdb
func onAccept(s *gotalk.Sock) {
	// Keep track of connected sockets
	socksmu.Lock()
	defer socksmu.Unlock()
	socks[s] = 1

	s.CloseHandler = func(s *gotalk.Sock, _ int) {
		socksmu.Lock()
		defer socksmu.Unlock()
		delete(socks, s)
	}

	// Send list of rooms
	roomsmu.RLock()
	defer roomsmu.RUnlock()
	s.Notify("rooms", rooms)

	// Assign the socket a random username
	username := randomName()
	s.UserData = username
	s.Notify("username", username)
}
示例#6
0
func onAccept(s *gotalk.Sock) {
	c := client.NewClient()
	s.UserData = c
	fmt.Printf("New accepted connection.  [%s]\n", c.ID)
}