示例#1
0
        static void Main(string[] args)
        {
            TClient tcp_client = new TClient();

            tcp_client.AddHandle(PACKET_TYPE.eEchoPacket, new TClient.Handler(HandleEchoPacket));
            tcp_client.AddHandle(PACKET_TYPE.eStringPacket, new TClient.Handler(HandleStringPacket));
            tcp_client.AddHandle(PACKET_TYPE.eAddResultpacket, new TClient.Handler(HandleAddResultPacket));
            tcp_client.Connect("127.0.0.1", 9000);
            while (true)
            {
/*
 *              string message = Console.ReadLine();
 *              if (message.IndexOf("END") > -1) break;
 *
 *              EchoPacket.Builder newTestPacketBuilder = EchoPacket.CreateBuilder();
 *              newTestPacketBuilder.SetId(10);
 *              newTestPacketBuilder.SetName(Util.StringToByteString(message, Encoding.Default)); // 문자열은 이와같은 변형을 반드시 필요로한다
 *              EchoPacket packet = newTestPacketBuilder.Build();
 *              newTestPacketBuilder = null;
 *              tcp_client.SendProtobuf(packet, PACKET_TYPE.eEchoPacket);
 */

                AddPacket.Builder packet_builder = AddPacket.CreateBuilder();
                Console.Write("first : ");
                packet_builder.SetFirst(InputInteger());
                Console.Write("second : ");
                packet_builder.SetSecond(InputInteger());
                AddPacket packet = packet_builder.Build();
                packet_builder = null;
                tcp_client.SendProtobuf(packet, PACKET_TYPE.eAddPacket);
            }
            tcp_client.Disconnect();
        }
示例#2
0
        public void Connect()
        {
            TClient.Connect(IPAddress.Parse(IP), Variables.Port); // Connect to the server

            Stream = TClient.GetStream();                         // Get the server stream

            PacketThread.Start();                                 // Start the packet update thread

            Variables.MainForm.IsClientConnected = true;
        }