Пример #1
0
        public void Setup()
        {
            ManualResetEvent mre = new ManualResetEvent(false);
            var cert             = new X509Certificate2(new SocketHelper().GetCertFileContents(), "Password");

            _server = new SimpleSocketTcpSslListener(cert);
            _client = new SimpleSocketTcpSslClient(cert);

            new Thread(() => _server.StartListening(13000)).Start();

            ClientConnectedDelegate con = (client) =>
            {
                _clientid = client.Id;
                mre.Set();
            };

            _contract = new MessageContractImpl();
            _client.AddMessageContract(_contract);
            _server.AddMessageContract(_contract);

            _server.ClientConnected += con;

            _client.StartClient("127.0.0.1", 13000);

            mre.WaitOne(10000);
            _server.ClientConnected -= con;
        }
Пример #2
0
        private static void ClientTask()
        {
            //using (var client = new SimpleSocketTcpClient())
            //{
            var client = new SimpleSocketTcpSslClient(cert);

            // var client = new SimpleSocketTcpClient();
            //var client = new SimpleSocketTcpSslClient(@"", "");
            _clientId++;
            client.MessageReceived   += ClientOnMessageReceived;
            client.ConnectedToServer += ClientOnConnectedToServer;
            client.ClientErrorThrown += ClientOnClientErrorThrown;
            client.MessageSubmitted  += ClientOnMessageSubmitted;
            client.MessageFailed     += ClientOnMessageFailed;
            client.StartClient("127.0.0.1", 13000);

            //Thread.Sleep(1000);

            for (int i = 0; i < _numMsg; i++)
            {
                Task.Delay(_random.Next(0, 25)).Wait();
                client.SendMessage("Test Message " + (i + 1));
            }

            //}

            Console.WriteLine("[CLIENT] has finished.");
        }
Пример #3
0
        private void initClient()
        {
            var t1 = Task.Run(() => {
                var client = new SimpleSocketTcpSslClient(_cert);
                _clients.Add(client);
                client.StartClient("127.0.0.1", 13000);
            });

            t1.Wait();
        }