Exemple #1
0
        /// <summary>
        ///     Runs a client disconnect test on the given listener and connection.
        /// </summary>
        /// <param name="listener">The listener to test.</param>
        /// <param name="connection">The connection to test.</param>
        internal static void RunClientDisconnectTest(NetworkConnectionListener listener, Connection connection)
        {
            ManualResetEvent mutex  = new ManualResetEvent(false);
            ManualResetEvent mutex2 = new ManualResetEvent(false);

            listener.NewConnection += delegate(NewConnectionEventArgs args)
            {
                args.Connection.Disconnected += delegate(object sender2, DisconnectedEventArgs args2)
                {
                    mutex2.Set();
                };

                mutex.Set();
            };

            listener.Start();

            connection.Connect();

            mutex.WaitOne();

            connection.Disconnect("Testing");

            mutex2.WaitOne();
        }
Exemple #2
0
        /// <summary>
        ///     Ensures a client sends a disconnect packet to the server on Dispose.
        /// </summary>
        /// <param name="listener">The listener to test.</param>
        /// <param name="connection">The connection to test.</param>
        internal static void RunClientDisconnectOnDisposeTest(NetworkConnectionListener listener, Connection connection)
        {
            ManualResetEvent mutex  = new ManualResetEvent(false);
            ManualResetEvent mutex2 = new ManualResetEvent(false);

            listener.NewConnection += delegate(NewConnectionEventArgs args)
            {
                args.Connection.Disconnected += delegate(object sender2, DisconnectedEventArgs args2)
                {
                    mutex2.Set();
                };

                mutex.Set();
            };

            listener.Start();

            connection.Connect();

            if (!mutex.WaitOne(TimeSpan.FromSeconds(1)))
            {
                Assert.Fail("Timeout waiting for client connection");
            }

            connection.Dispose();

            if (!mutex2.WaitOne(TimeSpan.FromSeconds(1)))
            {
                Assert.Fail("Timeout waiting for client disconnect packet");
            }
        }
Exemple #3
0
        /// <summary>
        ///     Runs a general test on the given listener and connection.
        /// </summary>
        /// <param name="listener">The listener to test.</param>
        /// <param name="connection">The connection to test.</param>
        internal static void RunClientToServerTest(NetworkConnectionListener listener, Connection connection, int dataSize, SendOption sendOption)
        {
            //Setup meta stuff
            byte[]           data   = BuildData(dataSize);
            ManualResetEvent mutex  = new ManualResetEvent(false);
            ManualResetEvent mutex2 = new ManualResetEvent(false);

            //Setup listener
            DataReceivedEventArgs?result = null;

            listener.NewConnection += delegate(NewConnectionEventArgs args)
            {
                args.Connection.DataReceived += delegate(DataReceivedEventArgs innerArgs)
                {
                    Trace.WriteLine("Data was received correctly.");

                    result = innerArgs;

                    mutex2.Set();
                };

                mutex.Set();
            };

            listener.Start();

            //Connect
            connection.Connect();

            mutex.WaitOne();

            connection.SendBytes(data, sendOption);

            //Wait until data is received
            mutex2.WaitOne();

            Assert.AreEqual(data.Length, result.Value.Message.Length);

            for (int i = 0; i < data.Length; i++)
            {
                Assert.AreEqual(data[i], result.Value.Message.ReadByte());
            }

            Assert.AreEqual(sendOption, result.Value.SendOption);
        }
Exemple #4
0
        /// <summary>
        ///     Runs a general test on the given listener and connection.
        /// </summary>
        /// <param name="listener">The listener to test.</param>
        /// <param name="connection">The connection to test.</param>
        internal static void RunServerToClientTest(NetworkConnectionListener listener, Connection connection, int dataSize, SendOption sendOption)
        {
            //Setup meta stuff
            byte[]           data  = BuildData(dataSize);
            ManualResetEvent mutex = new ManualResetEvent(false);

            //Setup listener
            listener.NewConnection += delegate(NewConnectionEventArgs ncArgs)
            {
                ncArgs.Connection.SendBytes(data, sendOption);
            };

            listener.Start();

            DataReceivedEventArgs?args = null;

            //Setup conneciton
            connection.DataReceived += delegate(DataReceivedEventArgs a)
            {
                Trace.WriteLine("Data was received correctly.");

                try
                {
                    args = a;
                }
                finally
                {
                    mutex.Set();
                }
            };

            connection.Connect();

            //Wait until data is received
            mutex.WaitOne();

            Assert.AreEqual(data.Length, args.Value.Message.Length);

            for (int i = 0; i < data.Length; i++)
            {
                Assert.AreEqual(data[i], args.Value.Message.ReadByte());
            }

            Assert.AreEqual(sendOption, args.Value.SendOption);
        }
Exemple #5
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(NetworkConnectionListener obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }
 public virtual void RemoveListenerAsync(byte messageType, NetworkConnectionListener oldListener)
 {
     SharingClientPINVOKE.NetworkConnection_RemoveListenerAsync(swigCPtr, messageType, NetworkConnectionListener.getCPtr(oldListener));
 }
 public virtual void AddListenerAsync(byte messageType, NetworkConnectionListener newListener)
 {
     SharingClientPINVOKE.NetworkConnection_AddListenerAsync(swigCPtr, messageType, NetworkConnectionListener.getCPtr(newListener));
 }
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(NetworkConnectionListener obj) {
   return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
 }
 public virtual void RemoveListenerAsync(byte messageType, NetworkConnectionListener oldListener) {
   SharingClientPINVOKE.NetworkConnection_RemoveListenerAsync(swigCPtr, messageType, NetworkConnectionListener.getCPtr(oldListener));
 }
 public virtual void AddListenerAsync(byte messageType, NetworkConnectionListener newListener) {
   SharingClientPINVOKE.NetworkConnection_AddListenerAsync(swigCPtr, messageType, NetworkConnectionListener.getCPtr(newListener));
 }
 public static extern void NetworkConnectionListener_director_connect(global::System.Runtime.InteropServices.HandleRef jarg1, NetworkConnectionListener.SwigDelegateNetworkConnectionListener_0 delegate0, NetworkConnectionListener.SwigDelegateNetworkConnectionListener_1 delegate1, NetworkConnectionListener.SwigDelegateNetworkConnectionListener_2 delegate2, NetworkConnectionListener.SwigDelegateNetworkConnectionListener_3 delegate3);