Exemple #1
0
        /// <summary>
        /// 鏈接指定地址的服務器 Connect remote server thread event.
        /// </summary>
        /// <param name="address">test address.</param>
        private void Connecting(object address)
        {
            // create connect remote machine class object instance ..
            ScanPort runConnect = new ScanPort();

            // 測試是否可連接 scanning ..
            if (!runConnect.Scan((IPAddress)address, (ushort)this.NumericUpDown_Port.Value))
            {
                resultVar = ConnectResult.FAILCONNECT;
            }
            else
            {
                resultVar = ConnectResult.SUCCESS;
            }
        }
        /// <summary>
        /// 建立Tcp鏈接 Start and connect remote service.
        /// </summary>
        /// <param name="IpAddr">connect server ip address.</param>
        /// <param name="Port">entry prot number.</param>
        /// <returns>System.Boolean</returns>
        public bool Connect(IPAddress IpAddr, ushort Port)
        {
            // create scan server port class object ..
            ScanPort Ping = new ScanPort();

            // ping renbar server can connect ..
            if (Ping.Scan(IpAddr, Port))
            {
                // connecting renbar center server ..
                ClientRequest = new TcpClientSocket(IpAddr, Port);
            }
            else
            {
                return(false);
            }
            return(true);
        }
Exemple #3
0
        private void SlaveThread()
        {
            ScanPort runConnect = null;
            bool     NoProtocol = true;//ProtocolBase、RenderBase未開啟

            try
            {
                // create object instance ..
                runConnect = new ScanPort();
                do
                {
                    //新增備援機制 是否是主機,如果不是建立連接測試類,如果可以連接主機,則不啟動備援,如果連接主機不通,則啟動備援機制
                    #region 本機是主機
                    if (EnvHostBase.LocalIpAddress.ToString() == Settings.Default.MasterServer)
                    {
                        if (NoProtocol)
                        {
                            this.OperationBase = new RenderBase(this.EnvData, this.EnvLog)
                            {
                                ConnectPort = this.__ListenRenderPort
                            };
                            this.PortalBase = new ProtocolBase(this.EnvData, this.EnvLog)
                            {
                                ConnectPort = this.__ListenRenderPort,
                                ListenPort  = this.__ListenClientPort,
                                MaxHistory  = this.__JobHistoryMaxRecord
                            };
                            //開啟監聽端口6601
                            this.MasterBase = new SlaveBase(this.EnvLog)
                            {
                                _listenSlavePort = this.__ServerSyncPort
                            };
                            NoProtocol = false;
                        }
                    }
                    #endregion

                    #region 本機非主機
                    else
                    {
                        //主機未啟動
                        if (!runConnect.Scan(System.Net.IPAddress.Parse(Settings.Default.MasterServer), this.__ServerSyncPort))
                        {
                            if (this.OperationBase == null)
                            {
                                this.OperationBase = new RenderBase(this.EnvData, this.EnvLog)
                                {
                                    ConnectPort = this.__ListenRenderPort
                                };
                            }
                            if (this.PortalBase == null)
                            {
                                this.PortalBase = new ProtocolBase(this.EnvData, this.EnvLog)
                                {
                                    ConnectPort = this.__ListenRenderPort,
                                    ListenPort  = this.__ListenClientPort,
                                    MaxHistory  = this.__JobHistoryMaxRecord
                                };
                            }
                        }
                        //主機已啟動
                        else
                        {
                            //取消与客户端以及render端沟通的线程
                            if (this.OperationBase != null)
                            {
                                this.OperationBase.Dispose();
                                this.OperationBase = null;
                            }
                            if (this.PortalBase != null)
                            {
                                this.PortalBase.Dispose();
                                this.PortalBase = null;
                            }
                        }
                    }

                    #endregion
                    Thread.Sleep(1000);
                } while (!requestStop);
            }
            catch (Exception ex)
            {
                string ExceptionMsg = ex.Message + "Master to Slave!";

                // write to log file ..
                //EnvLog.Writer(AssemblyInfoClass.ProductInfo, Log.Level.Error, ExceptionMsg, true);
            }
        }