Beispiel #1
0
        /// <summary>
        /// 服务器配置
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button3_Click(object sender, EventArgs e)
        {
            FormServConfig form2 = new FormServConfig();

            form2.ShowDialog();
        }
Beispiel #2
0
        /// <summary>
        /// 窗体初始化,包括配置数据文件
        /// </summary>
        private void formInit()
        {
            try
            {
                string gssipStr   = "";
                string gssportStr = "";
                //配置SQLITE文件
                PubConstant.SqliteConnStr = Application.StartupPath;
                string  sqlstr = "SELECT * FROM GSSCONFIG WHERE ID=1";
                DataSet ds     = DbHelperSQLite.Query(sqlstr);
                if (ds != null && ds.Tables[0] != null && ds.Tables[0].Rows != null)
                {
                    gssipStr   = ds.Tables[0].Rows[0]["GSSIP"].ToString().Trim();
                    gssportStr = ds.Tables[0].Rows[0]["GSSPORT"].ToString().Trim();
                }
                string.Format("ip:[{0}],port:[{1}]", gssipStr, gssportStr).Logger();
                if (gssipStr.Length > 0 && gssportStr.Length > 0)
                {
                    tGSSip.Text         = gssipStr;
                    tGSSport.Text       = gssportStr;
                    ShareData.LocalIp   = gssipStr;
                    ShareData.LocalPort = Convert.ToInt16(gssportStr);


                    //-------服务端通讯相关---------
                    IPAddress svripaddr = IPAddress.Parse(gssipStr);
                    ushort    uPort     = ushort.Parse(gssportStr);
                    svr           = new TcpSvr(svripaddr, uPort, 1024, new Coder(Coder.EncodingMothord.Default));
                    svr.Resovlver = new DatagramResolver("]$}");
                    //处理客户端连接数已满事件
                    svr.ServerFull += new NetEvent(this.ServerFull);
                    //处理新客户端连接事件
                    svr.ClientConn += new NetEvent(this.ClientConn);
                    //处理客户端关闭事件
                    svr.ClientClose += new NetEvent(this.ClientClose);
                    //处理接收到数据事件
                    svr.RecvData += new NetEvent(this.RecvData);
                    string Sstate = string.Format("{0}/{1}", svr.SessionCount, svr.Capacity);
                    lblServState.Text = Sstate;
                    //服务对客户端请求的处理实例
                    svrhandle = new ServerHandle(svr);

                    //日志记录
                    ShareData.Log.Info("GSS系统网络初始化" + gssipStr + ":" + gssportStr);

                    //开机自启动
                    string runstr = "";
                    try
                    {
                        RegistryKey ms_run = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
                        if (ms_run.GetValue("ShenLongYouSoft") != null)
                        {
                            runstr = ms_run.GetValue("ShenLongYouSoft").ToString();
                        }
                        timer1.Enabled = true;
                    }
                    catch (System.Exception ex)
                    {
                        ex.ToString().ErrorLogger();
                        ShareData.Log.Error("注册表查询失败", ex);
                    }


                    if (runstr.Trim().Length > 0)
                    {
                        checkBox1.Checked = true;
                        ServStart();
                    }
                }
                else
                {
                    FormServConfig form2 = new FormServConfig();
                    form2.ShowDialog();
                    Application.Restart();
                }
            }
            catch (System.Exception ex)
            {
                ex.ToString().ErrorLogger();
                MessageBox.Show("GSS初始化失败!\r\n" + ex.Message, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
                //日志记录
                ShareData.Log.Error("GSS初始化失败", ex);
                timer1.Enabled = false;
            }
        }