示例#1
0
 /// <summary>
 /// Starts to listen on a TCP port.
 /// </summary>
 /// <param name="listenAddress">The address to listen to.</param>
 /// <returns>True, if startup was successful.</returns>
 private bool StartupTcp(IPEndPoint listenAddress)
 {
     try
     {
         var pipeline = GetPipeline(true);
         _tcpServer = new MyTcpServer(listenAddress, pipeline);
         // rest of config done in MyTcpServer
         _tcpServer.Start();
         return(true);
     }
     catch (Exception ex)
     {
         Logger.Error("An exception occured when starting up TCP server.", ex);
         return(false);
     }
 }
示例#2
0
        public void FindOpenRandomPort_WhenCannotBindOnCurrentRandomPort_ShouldChooseAnotherPortAndBind()
        {
            //---------------Set up test pack-------------------
            using (var blocker = new MyTcpServer(2000))
            {
                blocker.Start();

                //---------------Assert Precondition----------------

                //---------------Execute Test ----------------------
                var another = new MyTcpServer();
                var result  = another._FindOpenRandomPort();
                Assert.AreEqual(2001, result);

                //---------------Test Result -----------------------
            }
        }
        public void FindOpenRandomPort_WhenCannotBindOnCurrentRandomPort_ShouldChooseAnotherPortAndBind()
        {
            //---------------Set up test pack-------------------
            using (var blocker = new MyTcpServer(2000))
            {
                blocker.Start();

                //---------------Assert Precondition----------------

                //---------------Execute Test ----------------------
                var another = new MyTcpServer();
                var result = another._FindOpenRandomPort();
                Assert.AreEqual(2001, result);

                //---------------Test Result -----------------------
            }
        }
示例#4
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            MyLogger       myLogger          = new MyLogger();
            BeginEndFilter receiveDataFilter = new BeginEndFilter();

            myTcpServer = new MyTcpServer(4000, receiveDataFilter, Encoding.UTF8, myLogger);
            myTcpServer.EnableKeepAlive      = true;
            myTcpServer.NewSessionConnected += MyTcpServer_NewSessionConnected;
            myTcpServer.SessionClosed       += MyTcpServer_SessionClosed;
            myTcpServer.NewRequestReceived  += MyTcpServer_NewRequestReceived;
            myTcpServer.Error += MyTcpServer_Error;
            myTcpServer.Start();

            string message = "Server start on:" + myTcpServer.ServerIP
                             + ":" + myTcpServer.ServerPort;

            myTcpServer.Logger.Log(message);
            this.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background,
                                        new Action(() =>
            {
                txt.AppendText(message + "\r\n\r\n");
                txt.ScrollToEnd();
            }));
        }