Пример #1
0
        public AramisTCPServer(ReceiveMessage receiveMessage, ArrayList allowedIP, string serverIP)
        {
            serverActive = false;
            NeedToUpdateIpList = new ArrayList();

            if (!SetConfiguration(allowedIP, serverIP))
                {
                return;
                }

            try
                {
                Console.WriteLine("\n\t***\tTCP Server [ {0} ] is ready.\n\n\n", IpAddress);
                TCPServer = new TcpListener(IPAddress.Parse(IpAddress), SERVER_PORT);

                }
            catch (Exception exp)
                {
                Console.WriteLine("Error during server creating: {0}.", exp.Message);
                Console.ReadLine();
                Application.Exit();
                return;
                }

            #region Creating CatchingConnection, Starting server

            try
                {
                ClientConnector = new CatchingConnections(TCPServer, AllowIpList, NeedToUpdateIpList,
                                                          WriteToFileAboutUpdate, FullUpdatePath, StringConnection,
                                                          receiveMessage);

                }
            catch (Exception e)
                {
                Console.WriteLine("Error CatchingConnections:" + e.Message);
                return;
                }

            CatchingConnectionThread = new Thread(ClientConnector.Start);
            CatchingConnectionThread.Name = "CatchingConnectionsThread";
            CatchingConnectionThread.IsBackground = true;

            try
                {
                TCPServer.Start();
                }
            catch (Exception exp)
                {
                Console.WriteLine("Error during server starting: {0}.", exp.Message);
                return;
                }

            CatchingConnectionThread.Start();

            #endregion

            serverActive = true;
        }
Пример #2
0
        public AramisTCPServer(ReceiveMessage receiveMessage, ArrayList allowedIP, string serverIP)
        {
            serverActive       = false;
            NeedToUpdateIpList = new ArrayList();

            if (!SetConfiguration(allowedIP, serverIP))
            {
                return;
            }

            try
            {
                Console.WriteLine("\n\t***\tTCP Server [ {0} ] is ready.\n\n\n", IpAddress);
                TCPServer = new TcpListener(IPAddress.Parse(IpAddress), SERVER_PORT);
            }
            catch (Exception exp)
            {
                Console.WriteLine("Error during server creating: {0}.", exp.Message);
                Console.ReadLine();
                Application.Exit();
                return;
            }

            #region Creating CatchingConnection, Starting server

            try
            {
                ClientConnector = new CatchingConnections(TCPServer, AllowIpList, NeedToUpdateIpList,
                                                          WriteToFileAboutUpdate, FullUpdatePath, StringConnection,
                                                          receiveMessage);
            }
            catch (Exception e)
            {
                Console.WriteLine("Error CatchingConnections:" + e.Message);
                return;
            }

            CatchingConnectionThread              = new Thread(ClientConnector.Start);
            CatchingConnectionThread.Name         = "CatchingConnectionsThread";
            CatchingConnectionThread.IsBackground = true;

            try
            {
                TCPServer.Start();
            }
            catch (Exception exp)
            {
                Console.WriteLine("Error during server starting: {0}.", exp.Message);
                return;
            }

            CatchingConnectionThread.Start();

            #endregion

            serverActive = true;
        }