public void TestTransportFile()
        {
            var path = TWDir.Test + "\\TestAsset.txt";
            var strm = new StreamWriter(File.OpenWrite(path));

            strm.Write("This is a test asset!");
            strm.Close();

            var spm = new SimpleServerPacketManager();
            var cpm = spm.CreateClient();

            var server = new ServerFileTransporter <DataPacket>("TestTrans", spm);

            server.Start();
            var client = new ClientFileTransporter <DataPacket>("TestTrans", cpm, TWDir.Test.CreateSubdirectory("TestTransportFileCache").FullName);

            var ct = server.GetClientTransporter(spm.Clients[0]);



            ct.SendFile(new DataPacket(), path);

            var info = client.ReceiveFile();



            // Test TestAsset file

            var lines = File.ReadAllLines(info.CachedFilePath);

            Assert.AreEqual(1, lines.Length);
            Assert.AreEqual("This is a test asset!", lines[0]);
        }
Example #2
0
        public void TestSimplePacketManagers()
        {
            var server  = new SimpleServerPacketManager();
            var success = new AutoResetEvent(false);

            var ts = new Thread(delegate()
            {
                var t = server.CreatePacketTransporter("DataPacket", new DataPacketFactory(), PacketFlags.TCP);
                t.EnableReceiveMode();
                var t2 = server.CreatePacketTransporter("DataPacket2", new DataPacketFactory(), PacketFlags.TCP);


                IClient client;

                while (t.PacketAvailable == false)
                {
                    Thread.Sleep(500);
                }

                var p = t.Receive(out client);

                Assert.AreEqual(p.Text, "Helloooo!");

                var tCl = t2.GetTransporterForClient(client);

                tCl.Send(new DataPacket("Hi there", 8888));
            });

            ts.Name = "ServerTestThread";
            ts.Start();

            var tc = new Thread(delegate()
            {
                var client = server.CreateClient();

                var t  = client.CreatePacketTransporter("DataPacket", new DataPacketFactory(), PacketFlags.TCP);
                var t2 = client.CreatePacketTransporter("DataPacket2", new DataPacketFactory(), PacketFlags.TCP);

                t.Send(new DataPacket("Helloooo!", 564));
                var p = t2.Receive();

                Assert.AreEqual(p.Text, "Hi there");

                success.Set();
            });

            tc.Name = "ClientTestThread";
            tc.Start();

            if (!success.WaitOne())
            {
                throw new Exception("Test timed out!");
            }
        }