Beispiel #1
0
        public void WriteToSocketServer()
        {
            const int   tcpPort      = 10097;
            TcpListener socketServer = null;

            try
            {
                socketServer = SocketServerHelper.Start(tcpPort);
                var ipAddress = "127.0.0.1";

                SimpleFileWriter.WriteLineToEventFile(DirectoryName.Diag, "Testing.");
                for (var testRun = 0; testRun < 2; testRun++)
                {
                    using (var tcpIpClient = new VaiTcpIpClient())
                    {
                        Assert.True(tcpIpClient.ConnectAsync(IPAddress.Parse(ipAddress), tcpPort).Result);
                        for (var i = 0; i < numSentMessages; i++)
                        {
                            var message = "Sample data " + i;
                            Assert.True(tcpIpClient.Write(message));
                            Task.Delay(TimeSpan.FromMilliseconds(100)).Wait();
                        }
                        Assert.True(tcpIpClient.Disconnect());
                    }
                }
            }
            finally
            {
                SocketServerHelper.Stop(null, socketServer);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Send some messages at even intervals using new tcpClient
        /// </summary>
        private async void SendTestDataWithNewTcpClientAsync(int tcpPort)
        {
            IPAddress ipAddress = IPAddress.Parse("127.0.0.1"); // DnsWrapper.GetPrimaryIp;

            using (var tcpIpClient = new VaiTcpIpClient())
            {
                bool ok = await tcpIpClient.ConnectAsync(ipAddress, tcpPort);

                Debug.Assert(ok, "Failed to connect to server");

                for (var i = 0; i < numSentMessages; i++)
                {
                    var msg = i + "ABC";
                    ok = tcpIpClient.Write(msg);
                    Debug.Assert(ok, "Failed to send message:" + msg);
                    Debug.WriteLine("Sending:" + msg);
                    Task.Delay(TimeSpan.FromMilliseconds(500)).Wait();
                }
                Debug.WriteLine("End send data.");
            }
        }