public void Initialize(ITraceProvider traceProvider) { TcpChannel channel = new TcpChannel(_server, _port, _bindIP, traceProvider); channel.Formatter = GetChannelFormatter(); RequestManager requestManager = new RequestManager(channel, _channelDisconnected); channel.Connect(); _requestManager = requestManager; try { initialized = InitializeInternal(); } catch (Exception) { channel.Disconnect(); _requestManager = null; throw; } if (!initialized) { channel.Disconnect(); _requestManager = null; } }
// [TestCase(400000, 100, 13348)] public void SendAndReceiveViaTcpTest(int length, int concurentLevel, int port) { TcpClient client; TcpClient serverClient; IntegrationTestsHelper.CreateTwoConnectedTcpClients(port, out client, out serverClient); var channelA = new TcpChannel(client); var channelB = new TcpChannel(serverClient); List <byte> recievedList = new List <byte>(length); int doneThreads = 0; Exception innerException = null; channelB.OnReceive += (_, msg) => { recievedList.AddRange(msg); if (recievedList.Count >= length) { byte lastValue = recievedList[0]; for (int i = 0; i < length; i++) { var val = recievedList[0]; recievedList.RemoveAt(0); try { Assert.AreEqual(lastValue, val, "Value is not as expected sience index " + i); } catch (Exception e) { innerException = e; } } doneThreads++; } }; channelB.AllowReceive = true; IntegrationTestsHelper.RunInParrallel <byte[]>(concurentLevel, (i) => { return(IntegrationTestsHelper.CreateArray(length, (byte)i)); }, (i, msg) => { channelA.Write(msg, 0, msg.Length); }); IntegrationTestsHelper.WaitOrThrow(() => (doneThreads >= concurentLevel), () => innerException); channelA.Disconnect(); channelB.Disconnect(); }
static void Main(string[] args) { var Server = new TcpChannel(1000000); Server.EventInform += (sender, packet) => Console.WriteLine(packet.Message); Server.GetInform += (sender, packet) => Console.WriteLine("Got: {0}", packet.Value); Server.CheckInform += (sender, packet) => { //if(!packet.Success) Console.WriteLine("[{0}] {1} => {2}", packet.Success ? "SUCCESS" : "FAIL", packet.Key, packet.Value); }; Server.GetAllInform += async (sender, packet) => { Console.WriteLine("Test: Data Coherence Test..."); foreach (var entity in packet.Table) await Server.Check(entity.Key, entity.Value); }; Server.Connected += async (sender) => { Console.WriteLine("Connected"); await sender.GetAll(); }; Server.Disconnected += (sender, error) => { Console.WriteLine("Disconnected : {0}", error); }; Task.Run(async () => await Server.Connect("127.0.0.1", 8002)); Console.WriteLine("Press any key to exit.."); Console.ReadKey(); Server.Disconnect(); }