Beispiel #1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                server                     = new HPSocketCS.SSLServer();
                server.VerifyMode          = SSLVerifyMode.Peer | SSLVerifyMode.FailIfNoPeerCert;
                server.CAPemCertFileOrPath = "ssl-cert\\ca.crt";
                server.PemCertFile         = "ssl-cert\\server.cer";
                server.PemKeyFile          = "ssl-cert\\server.key";
                server.KeyPassword         = "******";

                // 初始化ssl环境
                // 初始化ssl环境
                if (!server.Initialize())
                {
                    SetAppState(AppState.Error);
                    AddMsg("初始化ssl环境失败:" + Sdk.SYS_GetLastError());
                    return;
                }

                this.Text = title;
                // 本机测试没必要改地址,有需求请注释或删除
                this.txtIpAddress.ReadOnly = true;

                // 加个委托显示msg,因为on系列都是在工作线程中调用的,ui不允许直接操作
                AddMsgDelegate = new ShowMsg(AddMsg);


                // 设置服务器事件
                server.OnPrepareListen += new ServerEvent.OnPrepareListenEventHandler(OnPrepareListen);
                server.OnAccept        += new ServerEvent.OnAcceptEventHandler(OnAccept);
                server.OnSend          += new ServerEvent.OnSendEventHandler(OnSend);
                server.OnReceive       += new ServerEvent.OnReceiveEventHandler(OnReceive);
                server.OnClose         += new ServerEvent.OnCloseEventHandler(OnClose);
                server.OnShutdown      += new ServerEvent.OnShutdownEventHandler(OnShutdown);
                server.OnHandShake     += new ServerEvent.OnHandShakeEventHandler(OnHandShake);

                SetAppState(AppState.Stoped);
            }
            catch (Exception ex)
            {
                SetAppState(AppState.Error);
                AddMsg(ex.Message);
            }
        }
Beispiel #2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                server = new HPSocketCS.SSLServer();
                server.VerifyMode = SSLVerifyMode.Peer | SSLVerifyMode.FailIfNoPeerCert;
                server.CAPemCertFileOrPath = "ssl-cert\\ca.crt";
                server.PemCertFile = "ssl-cert\\server.cer";
                server.PemKeyFile = "ssl-cert\\server.key";
                server.KeyPasswod = "123456";

                this.Text = title;
                // 本机测试没必要改地址,有需求请注释或删除
                this.txtIpAddress.ReadOnly = true;

                // 加个委托显示msg,因为on系列都是在工作线程中调用的,ui不允许直接操作
                AddMsgDelegate = new ShowMsg(AddMsg);

                // 设置服务器事件
                server.OnPrepareListen += new TcpServerEvent.OnPrepareListenEventHandler(OnPrepareListen);
                server.OnAccept += new TcpServerEvent.OnAcceptEventHandler(OnAccept);
                server.OnSend += new TcpServerEvent.OnSendEventHandler(OnSend);
                server.OnReceive += new TcpServerEvent.OnReceiveEventHandler(OnReceive);
                server.OnClose += new TcpServerEvent.OnCloseEventHandler(OnClose);
                server.OnShutdown += new TcpServerEvent.OnShutdownEventHandler(OnShutdown);

                server.OnHandShake += new SSLEvent.OnHandShakeEventHandler(OnHandShake);

                SetAppState(AppState.Stoped);
            }
            catch (Exception ex)
            {
                SetAppState(AppState.Error);
                AddMsg(ex.Message);
            }
        }