コード例 #1
0
        public void ServerAndSyncClient()
        {
            var remoteServer = new ComplexServer(_ipEndPoint, 10, _encoding);
            var remoteSyncClient = new ComplexSyncClient(_ipEndPoint, _encoding);

            remoteServer.NewMessageReceived += remoteServer_NewMessageReceived;

            remoteServer.BeginListen();
            remoteSyncClient.Connect();

            var simpleMessage = new SimpleMessage
                {
                    MessageId = Guid.NewGuid(),
                    StringMessage = "selam"
                };

            remoteSyncClient.Send(simpleMessage);
            var response = remoteSyncClient.Receive()
                .CastObj<SimpleMessage>();

            remoteSyncClient.Disconnect();
            remoteServer.Close();

            Assert.AreEqual(simpleMessage.MessageId, response.MessageId);
        }
コード例 #2
0
        public void ServerAndAsyncClient()
        {
            var remoteServer = new ComplexServer(_ipEndPoint, 10, _encoding);
            var remoteAsyncClient = new ComplexAsycnClient(_ipEndPoint, _encoding);

            remoteServer.NewMessageReceived += remoteServer_NewMessageReceived;
            remoteAsyncClient.NewMessageReceived += remoteAsyncClient_NewMessagereceived;

            remoteServer.BeginListen();
            remoteAsyncClient.Connect();

            var simpleMessage = new SimpleMessage
                {
                    MessageId = Guid.NewGuid(),
                    StringMessage = "selam"
                };

            remoteAsyncClient.Send(simpleMessage);

            remoteAsyncClient.Disconnect();
            remoteServer.Close();

            Thread.Sleep(2000);
            Assert.IsTrue(_messageReceivedAsync);
        }