예제 #1
0
파일: TestClass.cs 프로젝트: sanderele1/Pak
 public bool Serialize(Stream stream)
 {
     using (ObjectStream MS = new ObjectStream(stream))
     {
         MS.WriteInt64(ID);
         MS.WriteInt32(Age);
         MS.WriteString(Name);
         MS.WriteData(Data);
     }
     return true;
 }
예제 #2
0
 public virtual bool Serialize(Stream stream)
 {
     using (ObjectStream OBS = new ObjectStream(stream))
     {
         OBS.WriteData(FileHash);
         OBS.WriteUInt64(FileVersion);
         OBS.WriteString(RemoteFilename);
         OBS.WriteData(Data);
     }
     return true;
 }
예제 #3
0
파일: Program.cs 프로젝트: sanderele1/Pak
        static void Main(string[] args)
        {
            #region TestCode
            /**
            Stopwatch SW1 = new Stopwatch();
            Stopwatch SW2 = new Stopwatch();

            SW1.Start();
            for (int i = 0; i < 1000000; i++)
            {
                TestClass P1 = new TestClass();
                TestClass P2 = new TestClass();
                using (MemoryStream MEM = new MemoryStream())
                {
                    P1.Serialize(MEM);
                    MEM.Position = 0;
                    P2.Deserialize(MEM);
                }
            }
            SW1.Stop();

            SW2.Start();
            for (int i = 0; i < 1000000; i++)
            {
                TestClass Person = new TestClass();

                BinaryFormatter BF = new BinaryFormatter();
                using (MemoryStream MS = new MemoryStream())
                {
                    BF.Serialize(MS, Person);
                    MS.Position = 0;
                    TestClass TargetPerson = (TestClass)BF.Deserialize(MS);
                }
            }
            SW2.Stop();

            Console.WriteLine("Pak: " + SW1.ElapsedMilliseconds);
            Console.WriteLine("Binary Formatter" + SW2.ElapsedMilliseconds);
            **/
            #endregion

            SerializableFile File = new SerializableFile();
            File.LoadFile(Environment.CurrentDirectory + @"\TestFile.dat");
            File.RemoteFilename = "TestFile.dat";

            Server.StartServer();
            Client.Connect("127.0.0.1", 8899);

            Server.OnClientPacketComplete += Server_OnClientPacketComplete;

                while (true)
                {
                    string Command = Console.ReadLine();

                    if (Command.ToLower() == "exit" || Command.ToLower() == "close")
                        break;

                    using (MemoryStream MS = new MemoryStream())
                    {
                        using (ObjectStream OBJS = new ObjectStream(MS))
                        {
                            OBJS.WriteString(Command);
                            Client.SendData(MS.ToArray(), 0, false);
                        }
                    }

                }
            Client.Dispose();
            Server.Dispose();
        }