/// <system>
 /// Uruchamianie serwera
 /// </system>
 static void Main(string[] args)
 {
     /// <system>
     /// Wywołanie metody uruchamiającej serwer
     /// </system>
     MyTcpServer.Server();
 }
Пример #2
0
 public MyDataComunication OpenCommunication(string ipAddress, Action <object> callbackDataForImageProcessing)
 {
     ImageServer = new MyTcpServer(NetworkConstants.LocalLisenerConnection, 27001);
     ImageClient = new MyTcpClient(ipAddress, 27001);
     VoiceClient = new MyUdpClient(ipAddress, 27000);
     VoiceServer = new MyUdpServer(NetworkConstants.LocalLisenerConnection, 27000);
     ReciveImageAndProcess(callbackDataForImageProcessing);
     GrabImageAndSend();
     RecordSoundAndSend();
     ReceiveAndPlaySound();
     return(this);
 }
Пример #3
0
            public void startClient(MyTcpServer srv, TcpClient inClientSocket, string clineNo)
            {
                this.srv          = srv;
                this.clientSocket = inClientSocket;
                this.clNo         = clineNo;
                this.ip           = inClientSocket.Client.RemoteEndPoint.ToString();
                sin            = new StreamReader(clientSocket.GetStream());
                sout           = new StreamWriter(clientSocket.GetStream());
                sout.AutoFlush = true;
                Thread ctThread = new Thread(doClient);

                ctThread.IsBackground = true;
                ctThread.Start();
            }
Пример #4
0
        private void MyTcpServer_Error(object sender, ErrorEventArgs e)
        {
            MyServerSession myServerSession = sender as MyServerSession;
            MyTcpServer     myTcpServer     = myServerSession.Server as MyTcpServer;
            string          message         = "Error occur on:" + myServerSession.IpEndPoint.Address.ToString()
                                              + ":" + myServerSession.IpEndPoint.Port + ", " + e.Exception.Message;

            myTcpServer.Logger.Log(message);
            this.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background,
                                        new Action(() =>
            {
                txt.AppendText(message + "\r\n\r\n");
                txt.ScrollToEnd();
            }));
        }
Пример #5
0
        private void MyTcpServer_NewSessionConnected(object sender, EventArgs e)
        {
            MyServerSession myServerSession = sender as MyServerSession;
            MyTcpServer     myTcpServer     = myServerSession.Server as MyTcpServer;
            string          message         = "New client connected:" + myServerSession.IpEndPoint.Address.ToString()
                                              + ":" + myServerSession.IpEndPoint.Port;

            myTcpServer.Logger.Log(message);
            this.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background,
                                        new Action(() =>
            {
                txt.AppendText(message + "\r\n\r\n");
                txt.ScrollToEnd();
            }));
        }
Пример #6
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);
     }
 }
Пример #7
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 -----------------------
            }
        }
Пример #8
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 -----------------------
            }
        }
Пример #9
0
        private void MyTcpServer_NewRequestReceived(object sender, DataEventArgs e)
        {
            MyServerSession myServerSession = sender as MyServerSession;
            MyTcpServer     myTcpServer     = myServerSession.Server as MyTcpServer;

            byte[] pureData = myTcpServer.ReceiveDataFilter.RemoveMessageFilterFlag(e.Data);
            string messageReceivedOrigin = myTcpServer.Encoding.GetString(e.Data);
            string message = myTcpServer.Encoding.GetString(pureData);

            this.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background,
                                        new Action(() =>
            {
                if (message.Length > 2000)
                {
                    txt.AppendText(message.Substring(0, 2000) + "\r\n......\r\n\r\n");
                }
                else
                {
                    txt.AppendText(message + "\r\n\r\n");
                }
                txt.ScrollToEnd();
            }));
        }
Пример #10
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();
            }));
        }