|
|
@@ -2,7 +2,6 @@
|
|
|
using System.Threading;
|
|
|
using System.Threading.Tasks;
|
|
|
using Common.Helper;
|
|
|
-using Common.Logger;
|
|
|
using Common.Network;
|
|
|
using NUnit.Framework;
|
|
|
using UNet;
|
|
|
@@ -28,7 +27,7 @@ namespace UNetTest
|
|
|
byte[] bytes = await channel.RecvAsync();
|
|
|
CollectionAssert.AreEqual("9876543210".ToByteArray(), bytes);
|
|
|
}
|
|
|
- barrier.RemoveParticipant();
|
|
|
+ this.barrier.RemoveParticipant();
|
|
|
}
|
|
|
|
|
|
private async void ServerEvent(IService service)
|
|
|
@@ -49,36 +48,38 @@ namespace UNetTest
|
|
|
const string hostName = "127.0.0.1";
|
|
|
const ushort port = 8889;
|
|
|
using (IService clientService = new UService(hostName, 8888))
|
|
|
- using (IService serverService = new UService(hostName, 8889))
|
|
|
- {
|
|
|
- Task task1 = Task.Factory.StartNew(() =>
|
|
|
+ {
|
|
|
+ using (IService serverService = new UService(hostName, 8889))
|
|
|
{
|
|
|
- while (!isClientStop)
|
|
|
+ Task task1 = Task.Factory.StartNew(() =>
|
|
|
{
|
|
|
- clientService.Update();
|
|
|
- }
|
|
|
- }, TaskCreationOptions.LongRunning);
|
|
|
+ while (!this.isClientStop)
|
|
|
+ {
|
|
|
+ clientService.Update();
|
|
|
+ }
|
|
|
+ }, TaskCreationOptions.LongRunning);
|
|
|
|
|
|
- Task task2 = Task.Factory.StartNew(() =>
|
|
|
- {
|
|
|
- while (!isServerStop)
|
|
|
+ Task task2 = Task.Factory.StartNew(() =>
|
|
|
{
|
|
|
- serverService.Update();
|
|
|
- }
|
|
|
- }, TaskCreationOptions.LongRunning);
|
|
|
+ while (!this.isServerStop)
|
|
|
+ {
|
|
|
+ serverService.Update();
|
|
|
+ }
|
|
|
+ }, TaskCreationOptions.LongRunning);
|
|
|
|
|
|
- // 往server host线程增加事件,accept
|
|
|
- serverService.Add(() => this.ServerEvent(serverService));
|
|
|
+ // 往server host线程增加事件,accept
|
|
|
+ serverService.Add(() => this.ServerEvent(serverService));
|
|
|
|
|
|
- Thread.Sleep(1000);
|
|
|
+ Thread.Sleep(1000);
|
|
|
|
|
|
- // 往client host线程增加事件,client线程连接server
|
|
|
- clientService.Add(() => this.ClientEvent(clientService, hostName, port));
|
|
|
- barrier.SignalAndWait();
|
|
|
+ // 往client host线程增加事件,client线程连接server
|
|
|
+ clientService.Add(() => this.ClientEvent(clientService, hostName, port));
|
|
|
+ this.barrier.SignalAndWait();
|
|
|
|
|
|
- serverService.Add(() => { isServerStop = true; });
|
|
|
- clientService.Add(() => { isClientStop = true; });
|
|
|
- Task.WaitAll(task1, task2);
|
|
|
+ serverService.Add(() => { this.isServerStop = true; });
|
|
|
+ clientService.Add(() => { this.isClientStop = true; });
|
|
|
+ Task.WaitAll(task1, task2);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|