Esempio n. 1
0
        public void SendReceive()
        {
            using (var peer1 = new PeerSocket("@inproc://peertopeer"))
                using (var peer2 = new PeerSocket())
                {
                    var peer1Identity = peer2.ConnectPeer("inproc://peertopeer");

                    peer2.SendMoreFrame(peer1Identity);
                    peer2.SendFrame("Hello");

                    // peer2 identity
                    var peer2Identity = peer1.ReceiveFrameBytes();
                    var msg           = peer1.ReceiveFrameString();

                    Assert.Equal("Hello", msg);

                    peer1.SendMoreFrame(peer2Identity);
                    peer1.SendFrame("World");

                    peer2.ReceiveFrameBytes();
                    msg = peer2.ReceiveFrameString();

                    Assert.Equal("World", msg);

                    peer1.SendMoreFrame(peer2Identity);
                    peer1.SendFrame("World2");

                    peer2.ReceiveFrameBytes();
                    msg = peer2.ReceiveFrameString();

                    Assert.Equal("World2", msg);
                }
        }
Esempio n. 2
0
        public void CanSendAfterUnreachableException()
        {
            using (var peer1 = new PeerSocket())
            {
                var wrongKey = new byte[] { 0, 0, 0, 0 };

                Assert.Throws <HostUnreachableException>(() => peer1.SendMoreFrame(wrongKey));

                using (var peer2 = new PeerSocket("@inproc://peertopeer"))
                {
                    var peer2Identity = peer1.ConnectPeer("inproc://peertopeer");

                    peer1.SendMoreFrame(peer2Identity);
                    peer1.SendFrame("Hello");

                    peer2.ReceiveFrameBytes();
                    var msg = peer2.ReceiveFrameString();

                    Assert.Equal("Hello", msg);
                }
            }
        }