Beispiel #1
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)
		}
	}()
}
Beispiel #2
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)
}