public void TestJsonPackageParser()
 {
     Lin.Comm.Tcp.JsonTestPackage test = new Lin.Comm.Tcp.JsonTestPackage();
     //Lin.Comm.Tcp.JsonTestPackage result = new Lin.Comm.Tcp.JsonTestPackage();
     //result.Parser(test.Write());
     //Console.WriteLine("result:" + result.Params);
     JsonProtocolParser parser = new JsonProtocolParser();
     parser.Put(test.Write());
     JsonTestPackage result = parser.GetPackage() as JsonTestPackage;
 }
Esempio n. 2
0
        public void TestTcpComm()
        {
            Lin.Comm.Tcp.Communicate server = new Lin.Comm.Tcp.Communicate((session,pack,response) =>
            {
                CommandPackage p = pack as CommandPackage;
                if (p != null)
                {
                    Console.WriteLine("pack:" + ((CommandPackage)pack).Command);
                }
                JsonPackage json = pack as JsonPackage;
                if (json != null)
                {
                    Console.WriteLine("json:" + json.Path);
                }
                //response(pack);
            }, 7890,new SessionListener());

            Lin.Comm.Tcp.Communicate client = new Lin.Comm.Tcp.Communicate((session, pack,response) =>
            {

            }, "127.0.0.1", 7890);

            Lin.Comm.Tcp.DetectPackage detect = new Lin.Comm.Tcp.DetectPackage();
            Package r = client.Send(detect).WaitForEnd();
            Console.WriteLine("----------------------------------"+r.Sequeue+r);

            Lin.Comm.Tcp.JsonTestPackage jsonPack = new JsonTestPackage();
            jsonPack.Data = "test.";
            r = client.Send(jsonPack).WaitForEnd();
            Console.WriteLine("----------------------------------" + r.Sequeue+r);

            //Thread.Sleep(1000);
            client.Close();

            server.Close();
            //Thread.Sleep(1000);
            Console.WriteLine("end .");
            //Console.ReadKey();
        }