Beispiel #1
0
 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;
 }
Beispiel #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;
 }
Beispiel #3
0
        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();
        }