Beispiel #1
0
        public async Task TestWithNoServer()
        {
            ECAPClient client = new ECAPClient(new ConnectionInfo()
            {
                HostName = Guid.NewGuid().ToString()
            });

            client.RetryWhenFails = false;

            bool failed = false;

            client.ConnectionRefused += (sender, e) => failed = true;

            await client.Start();

            Assert.IsTrue(failed);
        }
Beispiel #2
0
    /// <summary>
    /// The entry-point method.
    /// </summary>
    /// <param name="args">An optional command-line arguments in the following format: PropertyName=value.
    /// e.g: HostName=something or PortNumber=1234.</param>
    /// <returns></returns>
    public static async Task Main(string[] args)
    {
        Console.WriteLine("ECAP .NET Client Started.\r\n");

        // Instantiates a TCP Client based on the parsed command line arguments (or the default values)
        ECAPClient ecapClient = new ECAPClient(ConnectionInfo.FromArgs(args));

        #region Displaying connection status when changed
        ecapClient.Connecting            += (sender, e) => Console.WriteLine($"Connecting to {ecapClient.ConnectionInfo}..");
        ecapClient.ConnectionEstablished += (sender, e) => Console.WriteLine("Connection Established. Waiting new messages..");
        ecapClient.ConnectionLost        += (sender, e) => Console.WriteLine($"\r\nConnection to {ecapClient.ConnectionInfo} Lost.");
        ecapClient.ConnectionRefused     += (sender, e) => Console.WriteLine($"Couldn't connect to {ecapClient.ConnectionInfo}.");
        #endregion

        ecapClient.MessageReceived += (sender, e) => Console.Write(e.Message);

        // Starting the TCP client
        await ecapClient.Start();
    }
Beispiel #3
0
        public async Task TestReceivingAMessage()
        {
            string testMessage = "E";

            var serverTask = Task.Run(async() =>
            {
                await TCPSend(testMessage);
            });

            ECAPClient client = new ECAPClient(new ConnectionInfo())
            {
                RetryWhenFails = false
            };

            string messageReceived = null;

            client.MessageReceived += (sender, e) => { messageReceived = e.Message; e.WaitAnotherMessage = false; };

            await client.Start();

            Assert.IsTrue(messageReceived == testMessage);
        }