Пример #1
0
func (hub *Hub) processRequest(socket *mexsocket.MexSocket, req *message.Request) {

	if req == nil {
		return
	}

	switch req.MexType {

	//create a new answer and send it over the channel
	case message.Identity:
		answer := message.NewAnswerIdentity(socket.Id)
		socket.Send(answer)

	//get the list of connected clients, remove the current one and send it over the channel
	case message.List:

		//the resulting list is []interface{}
		list := set.Difference(hub.idSet, set.New(socket.Id)).List()

		//create new answer
		answer := new(message.Answer)
		answer.MexType = message.List
		answer.Payload = convertSetList(list)
		socket.Send(answer)

	case message.Relay:

		//create an answer containing the payload
		answer := message.NewAnswerRelay(req.Body)

		//call hub to send the message to the list of clients provided
		hub.Multicast(req.Receivers, answer)
	}
}
Пример #2
0
func (server *MockServer) newConnection(id uint64, s *mexsocket.MexSocket) {

	var req *message.Request
	for {
		req = new(message.Request)
		_, err := s.Read(req)

		if err != nil {
			log.Println("MocServer read error: ", err)
			break
		}

		if req.MexType == message.Identity {
			server.WriteTo(id, message.NewAnswerIdentity(id))
		}
	}
}