Example #1
0
        public void Start()
        {
            Logger.Info("Starting the tracker...");
            try
            {
                StartTracker(TrackerIdentity);
            }
            catch (ServerSocketException ex)
            {
                if (ex.ExceptionType == ServerSocketErrors.AddressAlreadyTaken)
                {
                    TrackerIdentity.IPEndPoint.Port++;
                    Logger.Critical($"Port Already taken retring with {TrackerIdentity.IPEndPoint.Port.ToString()}");
                    Start();
                    return;
                }

                Logger.Error("Socket Exception : " + ex.ExceptionType.ToString());
                return;
            }
            Logger.Info("Done.");
            Logger.Info("Event Setup...");
            EventSetup();
            Logger.Info("Done.");
            Logger.Info("Setup tracker xml");
            ServerXml.Setup();
            Logger.Info("Done.");
            AddSeverIdXML();
        }
        /// <summary>
        ///客户端服务程序(连接云服务器)
        /// </summary>
        private static void ApiSrvThread(object ob)
        {
            ServerXml oServerXml  = ob as ServerXml;
            int       iLastSecond = -1;
            DateTime  oNow;
            //string strApiUrl = "http://127.0.0.1:7788/";
            string strApiUrl = "http://127.0.0.1:" + oServerXml.API_Port + "/";
            RemoteCtrlInfoQueryServices service = new RemoteCtrlInfoQueryServices();
            WebServiceHost _serviceHost         = new WebServiceHost(service, new Uri(strApiUrl));

            //或者第二种方法:WebServiceHost _serviceHost = new WebServiceHost(typeof(PersonInfoQueryServices), new Uri("http://127.0.0.1:7788/"));
            try
            {
                //如果这里报错,IDE必须以管理员方式运行
                _serviceHost.Open();
                //LogHelper.WriteLog(string.Format("Socket {0}:{1}启动失败,请检查权限或端口是否被占用!", config.Ip, config.Port));
                LogHelp.Info("API 服务启动成功" + strApiUrl);
                while (m_ClientSvrthread.IsAlive)
                {
                    oNow = DateTime.Now;
                    //秒任务
                    SecondTask(ref iLastSecond, oNow);
                    Thread.Sleep(100);
                }
                _serviceHost.Close();
            }
            catch (System.Exception ex)
            {
                //LogHelper.WriteLog(string.Format("Socket {0}:{1}启动失败,请检查权限或端口是否被占用!", config.Ip, config.Port));
                LogHelp.Info(ex.Message);
                LogHelp.Info("如果提示:HTTP 无法注册 " + strApiUrl + ",尝试以管理员运行程雪");
            }
        }
Example #3
0
 /// <summary>
 /// 更新对象信息
 /// </summary>
 /// <param name="oServerXml"></param>
 public void UpdateModel(ServerXml oServerXml)
 {
     //目前只更新界面上的参数,不更新数据库的用户名密码ip
     XmlHelper.UpdateNode(DefParam.CONFIG_PATH_FILE, "PORT", oServerXml.Port);
     XmlHelper.UpdateNode(DefParam.CONFIG_PATH_FILE, "IP", oServerXml.Ip);
     XmlHelper.UpdateNode(DefParam.CONFIG_PATH_FILE, "ID", oServerXml.Id);
     XmlHelper.UpdateNode(DefParam.CONFIG_PATH_FILE, "API_PORT", oServerXml.API_Port);
 }
Example #4
0
 private void AddSeverIdXML()
 {
     Console.Write("Retreiving server datas from xml ");
     foreach (var si in ServerXml.GetServers())
     {
         Idlist.Add(new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp), si);
         Console.Write(".");
     }
     Console.WriteLine("Ok");
 }
Example #5
0
        static void Main(string[] args)
        {
            bool      stop      = false;
            ServerXml serverXml = new ServerXml();

            serverXml.ServerStarted();
            while (!stop)
            {
                try
                {
                    Console.WriteLine("If you want to stop Program, write exit");
                    string MainCommand = Console.ReadLine();;
                    if (MainCommand.Equals("exit"))
                    {
                        stop = true;
                    }
                }
                catch (System.Exception e) { stop = true; }
            }
        }
Example #6
0
        public bool AddServer(string field)
        {
            string[] ip = field.Split(':');

            if (!IPAddress.TryParse(ip[0], out IPAddress iPAddress))
            {
                return(false);
            }
            if (!int.TryParse(ip[1], out int port))
            {
                return(false);
            }

            var s = new ServerIdentity()
            {
                IPEndPoint = new IPEndPoint(iPAddress, port)
            };

            Idlist.AddIdentity(null, s); //TODO See Null
            ServerXml.AddServerToXml(s);
            return(true);
        }
Example #7
0
        /// <summary>
        /// 获取xml配置信息对象
        /// </summary>
        /// <returns></returns>
        public ServerXml GetModel()
        {
            DataSet   oDataSet   = XmlHelper.GetDataSet(DefParam.CONFIG_PATH_FILE, XmlHelper.XmlType.File);
            ServerXml oServerXml = new ServerXml();

            oServerXml.Port     = oDataSet.Tables["MAIN_FRM"].Rows[0]["PORT"].ToString();
            oServerXml.Ip       = oDataSet.Tables["MAIN_FRM"].Rows[0]["IP"].ToString();
            oServerXml.Id       = oDataSet.Tables["MAIN_FRM"].Rows[0]["ID"].ToString();
            oServerXml.API_Port = oDataSet.Tables["MAIN_FRM"].Rows[0]["API_PORT"].ToString();
            //oServerXml.Server_ip = oDataSet.Tables["SQL"].Rows[0]["SERVER_IP"].ToString();
            //oServerXml.User_name = oDataSet.Tables["SQL"].Rows[0]["USER_NAME"].ToString();
            //oServerXml.Password = oDataSet.Tables["SQL"].Rows[0]["PASSWORD"].ToString();


            oServerXml.Client_max_num    = oDataSet.Tables["SOCKET"].Rows[0]["CLIENT_MAX_NUM"].ToString();
            oServerXml.Socket_timeout_ms = oDataSet.Tables["SOCKET"].Rows[0]["SOCKET_TIMEOUT_MS"].ToString();
            oServerXml.File_Directory    = oDataSet.Tables["SOCKET"].Rows[0]["FILE_DIRECTORY"].ToString();



            return(oServerXml);
        }
Example #8
0
        /// <summary>
        /// 启动服务器端服务
        /// </summary>
        /// <param name="oServerXml">界面的xml参数</param>
        public void ServerSvrStart(ServerXml oServerXml)
        {
            var config = new SuperSocket.SocketBase.Config.ServerConfig()
            {
                Name                     = "SSServer",
                ServerTypeName           = "SServer",
                ClearIdleSession         = true, //60秒执行一次清理90秒没数据传送的连接
                ClearIdleSessionInterval = 60,
                IdleSessionTimeOut       = 90,
                MaxRequestLength         = 4096, //最大包长度
                Ip   = "Any",
                Port = Convert.ToInt32(oServerXml.Port),
                MaxConnectionNumber = 100000,
            };

            //var app = new MyServer();
            //LogHelper.SetOnLog(new LogHelper.LogEvent((m) =>
            //{
            //    txtAll.Text = string.Join(" ", m, "\r\n");
            //    txtAll.Select(txtAll.TextLength, 0);
            //    txtAll.ScrollToCaret();
            //}));
            mMyServer.Setup(config);
            if (!mMyServer.Start())
            {
                //LogHelper.WriteLog(string.Format("Socket {0}:{1}启动失败,请检查权限或端口是否被占用!", config.Ip, config.Port));
                LogHelp.Info(string.Format("Socket {0}:{1}启动失败,请检查权限或端口是否被占用!", config.Ip, config.Port));
            }


            //启动个线程
            m_MonitorDBThreadID = new Thread(MonitorDBThread);
            //主线程退出,此线程立刻退出
            m_MonitorDBThreadID.IsBackground = true;
            m_MonitorDBThreadID.Start();

            LogHelp.Info("监听数据库线程启动完成!");
        }
Example #9
0
 public bool AddServer(ServerIdentity id, Socket server)
 {
     Idlist.AddIdentity(server, id);
     ServerXml.AddServerToXml(id);
     return(true);
 }
Example #10
0
 /// <summary>
 /// 加载窗体参数
 /// </summary>
 private void LoadFrmCfg()
 {
     mServerXml = new ServerXmlBLL().GetModel();
     this.integerInputPort.Value    = Convert.ToInt32(mServerXml.Port);
     this.integerInputAPIPort.Value = Convert.ToInt32(mServerXml.API_Port);
 }
Example #11
0
 /// <summary>
 /// 更新界面配置信息到xml
 /// </summary>
 /// <param name="oServerXml"></param>
 public void UpdateModel(ServerXml oServerXml)
 {
     mServerXmlDAL.UpdateModel(oServerXml);
 }