Beispiel #1
0
        public MainConnect
        (
            Socket main_server,
            ISQLDataBase sqldb,
            string user_info_path,
            string group_info_path,
            string applies_info_path,
            string chat_path,
            string cloud_path,
            string cloud_info_path,
            Action <LogLevel, string> notify,
            Action close
        )
        {
            IsClosed  = false;
            CloseLock = 0;

            Notify            = notify;
            SQLDB             = sqldb;
            UserInfoReader    = new KXTUserInfoReader(user_info_path, Notify);
            GroupInfoReader   = new KXTGroupInfoReader(group_info_path, Notify);
            UserAppliesReader = new KXTUserAppliesReader(applies_info_path, Notify);
            UserChatReader    = new KXTUserChatReader(chat_path, Notify);
            CloudReader       = new CloudInfoReader(cloud_info_path, Notify);
            CloudRootPath     = cloud_path;

            CloseServer = close;

            HeartTest = false;
            Timer     = new System.Timers.Timer
            {
                Interval  = HeartRequestInterval,
                AutoReset = false
            };
            Timer.Elapsed += HeartRequest_Trigger;
            Timer.Start();

            CacheTime = new System.Timers.Timer
            {
                Interval  = CacheVaildTime,
                AutoReset = false
            };
            CacheTime.Elapsed += CacheFresh_Trigger;
            Timer.Start();

            EmailRequestCache    = new ConcurrentDictionary <Guid, EmailRequestPackage>();
            OperationFinishCache = new ConcurrentDictionary <Guid, KeyValuePair <string, DateTime> >();

            MainServer = main_server;
            Buffer     = new byte[Datagram.DatagramLengthMax];
            MainServer.BeginReceive(Buffer, 0, Buffer.Length, SocketFlags.None, OnReceive, null);
        }
Beispiel #2
0
        public LoginServer
        (
            IPEndPoint service_point,
            string user_info_path,
            string group_info_path,
            string applies_info_path,
            string chat_path,
            string cloud_path,
            string cloud_info_path,
            IController controller
        )
        {
            Controller = controller;

            Connect = null;

            try
            {
                SQLDB = new SQLDataBase(DBStaticData.DataBaseConnString);
                SQLDB.Open();
            }
            catch (Exception e)
            {
                throw e;
            }

            UserInfoPath    = user_info_path;
            GroupInfoPath   = group_info_path;
            AppliesInfoPath = applies_info_path;
            ChatPath        = chat_path;
            CloudPath       = cloud_path;
            CloudInfoPath   = cloud_info_path;

            ServerSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            ServerSocket.Bind(service_point);

            Controller.SetActuallPort((ServerSocket.LocalEndPoint as IPEndPoint).Port);

            ServerSocket.Listen(1000);
            ServerSocket.BeginAccept(OnReceive, null);

            Controller.ServerStateChanged(ServerState.WAITING);
            Controller.Notify(LogLevel.Info, "已在 " + ServerSocket.LocalEndPoint + " 上启动服务");
        }