Esempio n. 1
0
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
}
Esempio n. 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
}
Esempio n. 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))
	}
}
Esempio n. 4
0
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)
		}
	}()
}
Esempio n. 5
0
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)
}
Esempio n. 6
0
func onAccept(s *gotalk.Sock) {
	c := client.NewClient()
	s.UserData = c
	fmt.Printf("New accepted connection.  [%s]\n", c.ID)
}