Esempio n. 1
0
        public void PreStartStatus()
        {
            MyListener listener = new MyListener();

            Assert.AreEqual(false, listener.IsActive, "#01");
            Assert.IsTrue(null != listener.GetSocket(), "#02");
            try {
                listener.AcceptSocket();
                Assert.Fail("Exception not thrown");
            } catch (InvalidOperationException) {
            }

            try {
                listener.AcceptTcpClient();
                Assert.Fail("Exception not thrown");
            } catch (InvalidOperationException) {
            }

            try {
                listener.Pending();
                Assert.Fail("Exception not thrown");
            } catch (InvalidOperationException) {
            }

            listener.Stop();
        }
Esempio n. 2
0
        private void Listen()
        {
            while (Running)
            {
                //Accept a new connection
                if (!MyListener.Pending())
                {
                    Thread.Sleep(500);
                    continue;
                }
                TcpClient client = MyListener.AcceptTcpClient();
                Trace.WriteLine(MESSAGE_SOCKET_TYPE + client.Client.SocketType);
                if (client.Connected == false)
                {
                    continue;
                }

                Trace.WriteLine(MESSAGE_CLIENT_CONNECTED + client.Client.RemoteEndPoint);
                try
                {
                    ServeClient(client.GetStream());
                }
                catch (IOException)
                {
                    Trace.WriteLine(MESSAGE_LOST_CONNECTION);
                }
                catch (ObjectDisposedException)
                {
                    Trace.WriteLine(MESSAGE_LOST_CONNECTION);
                }
                client.Close();
            }
            MyListener.Stop();
            Trace.WriteLine(MESSAGE_LISTENING_STOP);
        }
Esempio n. 3
0
		public void PreStartStatus ()
		{
			MyListener listener = new MyListener ();
			Assert.AreEqual (false, listener.IsActive, "#01");
			Assert.IsTrue (null != listener.GetSocket (), "#02");
			try {
				listener.AcceptSocket ();
				Assert.Fail ("Exception not thrown");
			} catch (InvalidOperationException) {
			}

			try {
				listener.AcceptTcpClient ();
				Assert.Fail ("Exception not thrown");
			} catch (InvalidOperationException) {
			}

			try {
				listener.Pending ();
				Assert.Fail ("Exception not thrown");
			} catch (InvalidOperationException) {
			}

			listener.Stop ();
		}