Exemplo n.º 1
0
func ReadRtn(conn net.Conn) {
	log.Printf("Daemon Thread for read in message start \n")
	for {
		rpacket := client.NewPacket()
		packetR := client.NewPacketReader(conn)
		rpacket, err := packetR.ReadPacket()
		if err != nil {
			log.Println("read errors: %s", err)
			time.Sleep(time.Second * 5)
		}
		client.INQUEUE <- *rpacket
		log.Println("Read SuccessPacket successfully and SuccessPacket:=", rpacket)
	}
}
Exemplo n.º 2
0
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())
	PrintInfoList()
	var err error
	conn, err := net.Dial("tcp", "127.0.0.1:1114")
	if err != nil {
		log.Panicf("error connetion:%s", err)
	}

	go ReadRtn(conn)
	go OutPacketProcessor(conn)

	packet := client.NewPacket()
	for {
		var data1 = make([]byte, 2048)
		fmt.Print("请输入你要选择的操作:")
		_, err := fmt.Scan(&data1)
		if err != nil {
			fmt.Println("数据输入异常:", err.Error())
		}
		if string(data1) == "1" {
			fmt.Println("1")
			packet.SetType(client.PacketType_GetLoginToken)
			loginToken := &protos.GetLoginToken{}
			loginToken.ClientType = proto.String("pc")
			bytes, err := proto.Marshal(loginToken)
			if err != nil {
				panic(err)
			}
			packet.SetData(bytes)
			client.OUTQEUE <- *packet
		}
	}
	/*for {
		var data1 = make([]byte, 2048)
		fmt.Print("请输入要发送的消息:")
		n, err := fmt.Scan(&data1)
		if err != nil {
			fmt.Println("数据输入异常:", err.Error())
		}
		log.Printf("%d--->%s", n, string(data1))
		packet.SetData(data1)
		client.OUTQEUE<-*packet
	}*/

}