Exemple #1
0
func outerConnectHandler(client *pillx.Response, protocol pillx.IProtocol) {
	clients[client.GetConn().Id] = client
	fmt.Printf("client %d 连接到此网关\n", client.GetConn().Id)

	//频道
	chat_channel.Subscribe(client)
}
Exemple #2
0
func helloHandler(client *pillx.Response, protocol pillx.IProtocol) {
	fmt.Println("test3")
	req := protocol.(*pillx.GateWayProtocol)
	fmt.Printf("%x", req.Header)
	fmt.Printf("%s", req.Content)
	req.Content = []byte("user" + strconv.FormatUint(req.Header.ClientId, 10) + ":  " + string(req.Content) + "\r\n")
	req.Header.Size = uint16(len(req.Content))
	client.Send(req)
}
Exemple #3
0
func helloHandler(client *pillx.Response, req pillx.IProtocol) {
	//fmt.Print(string(req.Content))
	//
	client.Send(req)
	//io.WriteString(client, "World")

	channel := pillx.NewChannel("all")
	channel.Subscribe(client)
	channel.Publish(req)
}
Exemple #4
0
func outerMessageHandler(client *pillx.Response, protocol pillx.IProtocol) {
	//将客户端协议转化为gateway协议
	gatewayProtocol := &pillx.GateWayProtocol{}
	header := &pillx.GatewayHeader{}
	gatewayProtocol.Header = header

	header.ClientId = client.GetConn().Id
	req := protocol.(*pillx.TextProtocol)
	header.Cmd = 0x0DDC
	header.Error = 0x0000
	header.Mark = 0xA8
	header.Size = uint16(len(req.Content))
	gatewayProtocol.Content = req.Content

	//发送给一个合适的worker
	worker := workers[worker_id]
	fmt.Printf("%x", gatewayProtocol.Header)
	fmt.Printf("%s", req.Content)
	worker.Send(gatewayProtocol)
	fmt.Printf("发送给worker %d\n", worker_id)
}
Exemple #5
0
func outerCloseHandler(client *pillx.Response, protocol pillx.IProtocol) {
	delete(clients, client.GetConn().Id)
}