Ejemplo n.º 1
0
        public clt_uc()
        {
            InitializeComponent();

            global_class = new global();
            var parser = new FileIniDataParser();

            data = parser.ReadFile("app_set.ini");

            uptime = init_cls.GETUpTime;

            client = ScsClientFactory.CreateClient(new ScsTcpEndPoint(data["NETWORK"]["MULTI_IP"], int.Parse(data["NETWORK"]["MULTI_PORT"])));
            client.MessageReceived += Client_MessageReceived;
            client.Disconnected    += Client_Disconnected;

            refreshUptime.Elapsed  += new ElapsedEventHandler(refreshTime);
            refreshProcess.Elapsed += new ElapsedEventHandler(refreshProcs);
            refreshConn.Elapsed    += RefreshConn_Elapsed;
            refreshHD.Elapsed      += RefreshHD_Elapsed;

            //refreshProcess.Enabled = true;
            refreshHD.Enabled = true;
            refreshHD.Start();
            //refreshProcess.Start();

            ConnectToServer();
            checkUpdate();
        }
Ejemplo n.º 2
0
        public virtual bool Connect(string remote_ip, int remote_port, int timeout = 10000)
        {
            try
            {
                this.ServerIp   = remote_ip;
                this.ServerPort = remote_port;

                EzWireProtocol protocol = new EzWireProtocol();
                protocol.DataReceived += protocol_DataReceived;//接收到数据,但不一定是message

                _client = ScsClientFactory.CreateClient(new ScsTcpEndPoint(remote_ip, remote_port));
                _client.WireProtocol     = protocol;
                _client.Connected       += client_Connected;
                _client.Disconnected    += client_Disconnected;
                _client.MessageReceived += client_MessageReceived;
                _client.ConnectTimeout   = timeout;
                _client.Connect();

                this._remain_life_number = this.DefaultLifeNumber;

                Helper.start_timer(ref _1s_timer, "1s timer", 1000, _1s_timer_Elapsed);
            }
            catch (Exception ex)
            {
                EzLogger.GlobalLogger.warning(string.Format("{0}{2}{1}{2}",
                                                            ex.Message, ex.StackTrace, Environment.NewLine));

                Dispose();

                return(false);
            }
            return(true);
        }
Ejemplo n.º 3
0
        public virtual void Dispose()
        {
            Helper.stop_timer(ref _1s_timer, "1s timer");

            try { _client.Disconnect(); }
            catch { }
            _client = null;
        }
        //--methods

        public UserAuthenticationState(IScsClient client, string login)
        {
            scsClient = client;

            client.Disconnected += Client_Disconnected;

            Console.WriteLine("Send AuthenticationMessage " + login);
            client.SendMessage(new AuthenticationMessage(login));
        }
Ejemplo n.º 5
0
 public void Connect(int clientId, string ip, int port)
 {
     _clientId  = clientId;
     _tcpClient = ScsClientFactory.CreateClient(new ScsTcpEndPoint(ip, port));
     _tcpClient.WireProtocol     = new AtmProtocol();
     _tcpClient.MessageReceived -= OnMessageReceived;
     _tcpClient.MessageReceived += OnMessageReceived;
     _tcpClient.Connect();
 }
Ejemplo n.º 6
0
        public ConnectionServices(string ip, int port)
        {
            _tcpClient = ScsClientFactory.CreateClient(new ScsTcpEndPoint(ip, port));
            _tcpClient.WireProtocol = new HsmProtocol();

            _tcpClient.MessageReceived -= OnMessageReceived;

            _tcpClient.MessageReceived += OnMessageReceived;
            _tcpClient.Connect();
        }
Ejemplo n.º 7
0
 /// <summary>
 /// 启动
 /// </summary>
 public void Start()
 {
     tcpClient = ScsClientFactory.CreateClient(new ScsTcpEndPoint(ServerIP, ServerPort));
     crc       = new ClientReConnecter(tcpClient);
     tcpClient.Disconnected    += new EventHandler(RouteServer_Disconnected);
     tcpClient.Connected       += new EventHandler(RouteServer_Connected);
     tcpClient.ConnectTimeout   = 30;
     tcpClient.MessageReceived += new EventHandler <MessageEventArgs>(RouteServer_MessageReceived);
     tcpClient.MessageSent     += new EventHandler <MessageEventArgs>(RouteServer_MessageSent);
     tcpClient.Connect();
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Creates a new ScsServiceClient object.
 ///
 /// </summary>
 /// <param name="client">Underlying IScsClient object to communicate with server</param><param name="clientObject">The client object that is used to call method invokes in client side.
 ///             May be null if client has no methods to be invoked by server.</param>
 public ScsServiceClient(IScsClient client, object clientObject)
 {
     this._client                = client;
     this._clientObject          = clientObject;
     this._client.Connected     += new EventHandler(this.Client_Connected);
     this._client.Disconnected  += new EventHandler(this.Client_Disconnected);
     this._requestReplyMessenger = new RequestReplyMessenger <IScsClient>(client);
     this._requestReplyMessenger.MessageReceived += new EventHandler <MessageEventArgs>(this.RequestReplyMessenger_MessageReceived);
     this._realServiceProxy = new AutoConnectRemoteInvokeProxy <T, IScsClient>(this._requestReplyMessenger, (IConnectableClient)this);
     this.ServiceProxy      = (T)this._realServiceProxy.GetTransparentProxy();
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Disconnects from server if it is connected.
        /// </summary>
        private void Disconnect()
        {
            if (_scsClient != null && _scsClient.CommunicationState == CommunicationStates.Connected)
            {
                try
                {
                    _scsClient.Disconnect();
                }
                catch (Exception) { }

                _scsClient = null;
            }
        }
Ejemplo n.º 10
0
        public void ParseMessage(IScsClient client, string message)
        {
            var command      = Commands.Instance.GetMessageCommand(message);
            var commandClass = _commands.FirstOrDefault(x => x.CommandText.Equals(command));

            try
            {
                commandClass?.Run(_sdjMainViewModel, Commands.Instance.GetMessageParameters(message));
            }
            catch (Exception e)
            {
                new ExceptionLogger(e);
            }
        }
Ejemplo n.º 11
0
        public InnerNetworkClient(string Address, int Port)
        {
            BindAddress = Address;
            BindPort = Port;

            InnerClient = ScsClientFactory.CreateClient(new ScsTcpEndPoint(BindAddress, BindPort));
            InnerClient.WireProtocol = new InnerWireProtocol();

            InnerClient.Connected += OnConnected;
            InnerClient.Disconnected += OnDisconnected;
            InnerClient.MessageReceived += OnMessageReceived;

            innerNetworkClient = this;
        }
Ejemplo n.º 12
0
        public InnerNetworkClient(string Address, int Port)
        {
            BindAddress = Address;
            BindPort    = Port;

            InnerClient = ScsClientFactory.CreateClient(new ScsTcpEndPoint(BindAddress, BindPort));
            InnerClient.WireProtocol = new InnerWireProtocol();

            InnerClient.Connected       += OnConnected;
            InnerClient.Disconnected    += OnDisconnected;
            InnerClient.MessageReceived += OnMessageReceived;

            innerNetworkClient = this;
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Creates a new ScsServiceClient object.
        /// </summary>
        /// <param name="client">Underlying IScsClient object to communicate with server</param>
        /// <param name="clientObject">The client object that is used to call method invokes in client side.
        /// May be null if client has no methods to be invoked by server.</param>
        public ScsServiceClient(IScsClient client, object clientObject)
        {
            _client       = client;
            _clientObject = clientObject;

            _client.Connected    += Client_Connected;
            _client.Disconnected += Client_Disconnected;

            _requestReplyMessenger = new RequestReplyMessenger <IScsClient>(client);
            _requestReplyMessenger.MessageReceived += RequestReplyMessenger_MessageReceived;

            _realServiceProxy = new AutoConnectRemoteInvokeProxy <T, IScsClient>(_requestReplyMessenger, this);
            ServiceProxy      = (T)_realServiceProxy.GetTransparentProxy();
        }
Ejemplo n.º 14
0
        static void Main(string[] args)
        {
            Thread th = new Thread(new ThreadStart(SendHandShake));

            th.Start();
            tcpClient = ScsClientFactory.CreateClient(new ScsTcpEndPoint("192.168.10.192", 2000));
            ClientReConnecter crc = new ClientReConnecter(tcpClient);

            tcpClient.Disconnected    += new EventHandler(ExchangeServer_Disconnected);
            tcpClient.Connected       += new EventHandler(ExchangeServer_Connected);
            tcpClient.ConnectTimeout   = 30;
            tcpClient.MessageReceived += new EventHandler <MessageEventArgs>(ExchangeServer_MessageReceived);
            tcpClient.MessageSent     += new EventHandler <MessageEventArgs>(ExchangeServer_MessageSent);
            tcpClient.Connect();
        }
Ejemplo n.º 15
0
        /// <summary>
        /// 实例化ServiceMessage
        /// </summary>
        /// <param name="node"></param>
        /// <param name="logger"></param>
        public ServiceRequest(ServerNode node, ILog logger, bool isTimeoutDisconnect)
        {
            this.logger = logger;
            this.node = node.Key;
            this.ip = node.IP;
            this.port = node.Port;

            this.client = ScsClientFactory.CreateClient(new ScsTcpEndPoint(ip, port));
            this.client.ConnectTimeout = 5000;
            this.client.IsTimeoutDisconnect = isTimeoutDisconnect;
            this.client.Disconnected += client_Disconnected;
            this.client.MessageReceived += client_MessageReceived;
            this.client.MessageSent += client_MessageSent;
            this.client.MessageError += client_MessageError;
            this.client.WireProtocol = new CustomWireProtocol(node.Compress, node.Encrypt);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// 实例化ServiceMessage
        /// </summary>
        /// <param name="node"></param>
        /// <param name="logger"></param>
        public ServiceRequest(ServerNode node, ILog logger, bool isTimeoutDisconnect)
        {
            this.logger = logger;
            this.node   = node.Key;
            this.ip     = node.IP;
            this.port   = node.Port;

            this.client = ScsClientFactory.CreateClient(new ScsTcpEndPoint(ip, port));
            this.client.ConnectTimeout      = 5000;
            this.client.IsTimeoutDisconnect = isTimeoutDisconnect;
            this.client.Disconnected       += client_Disconnected;
            this.client.MessageReceived    += client_MessageReceived;
            this.client.MessageSent        += client_MessageSent;
            this.client.MessageError       += client_MessageError;
            this.client.WireProtocol        = new CustomWireProtocol(node.Compress, node.Encrypt);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// 启动
        /// </summary>
        public void Start()
        {
            // handle recieved message
            ThreadPool.QueueUserWorkItem(new WaitCallback(HandleRecvMsg_Thread));

            //shake handle with server
            ThreadPool.QueueUserWorkItem(new WaitCallback(SharkHands_Thread), Controller.GetInstance().SharkHandsInterval);

            tcpClient = ScsClientFactory.CreateClient(new ScsTcpEndPoint(ExchangeServerIP, ExchangeServerPort));
            ClientReConnecter crc = new ClientReConnecter(tcpClient);

            tcpClient.Disconnected    += new EventHandler(ExchangeServer_Disconnected);
            tcpClient.Connected       += new EventHandler(ExchangeServer_Connected);
            tcpClient.ConnectTimeout   = 30;
            tcpClient.MessageReceived += new EventHandler <MessageEventArgs>(ExchangeServer_MessageReceived);
            tcpClient.MessageSent     += new EventHandler <MessageEventArgs>(ExchangeServer_MessageSent);
            tcpClient.Connect();
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Connects to the server.
        /// It automatically Logins to server if connection success.
        /// </summary>
        private void Connect(string serverIpAddress, int serverTcpPort)
        {
            //Disconnect if currently connected
            Disconnect();

            //Create a SCS client to connect to SCS server
            _scsClient = ScsClientFactory.CreateClient(new ScsTcpEndPoint(serverIpAddress, serverTcpPort));

            _scsClient.ConnectTimeout = 3;

            //Register events of SCS client
            _scsClient.Connected       += this.ScsClientConnected;
            _scsClient.Disconnected    += this.ScsClientDisconnected;
            _scsClient.MessageReceived += this.ScsClientMessageReceived;


            //Connect to the server
            _scsClient.Connect();
        }
Ejemplo n.º 19
0
        //---methods

        public ScsClient(string login, string ip, int tcpPort)
        {
            _login = login;

            //Синхронная очередь клиентских событий
            _eventQueue = new ConcurrentEventQueue();

            _msgReaders = new MsgReadersCollection();
            _msgReaders.RegisterMsgReader <AuthenticationSuccesMessage>(AuthenticationSuccessMsgReader);

            //Синхронная очередь msg с сервера
            _msgQueue = new ConcurrentMsgQueue(_msgReaders);

            _client               = ScsClientFactory.CreateClient(new ScsTcpEndPoint(ip, tcpPort));
            _client.Connected    += Client_Connected;
            _client.Disconnected += Client_Disconnected;

            _msgQueue.AddMessenger(_client);
        }
Ejemplo n.º 20
0
        public void Start()
        {
            try
            {
                Log.Warn("Connecting to server at {0} : {1} ", Category.System, IpAddress, Port);
                _client = ScsClientFactory.CreateClient(new ScsTcpEndPoint(IpAddress, Port));

                _client.WireProtocol = new AuthProtocol();

                _client.MessageReceived += OnReceiveMessage;
                _client.Connected       += OnConnected;
                _client.Disconnected    += OnDisconected;
                _client.Connect();
            }
            catch (Exception ex)
            {
                Log?.Exception(ex, "Starting Client");
            }
        }
Ejemplo n.º 21
0
        private void ConnectClick(object sender, RoutedEventArgs e)
        {
            string ip = txtIp.Text.Trim();

            if (string.IsNullOrWhiteSpace(ip) || string.IsNullOrWhiteSpace(txtPort.Text.Trim()))
            {
                MessageBox.Show("请填写IP及端口号!");
                return;
            }
            int port = 0;

            if (!int.TryParse(txtPort.Text.Trim(), out port))
            {
                MessageBox.Show("端口号必须为数字!");
                return;
            }
            try
            {
                //Create a client object to connect a server on 127.0.0.1 (local) IP and listens 10085 TCP port
                client = ScsClientFactory.CreateClient(new ScsTcpEndPoint(ip, port));
                // client.WireProtocol = new CustomWireProtocol(); //Set custom wire protocol
                //Register to MessageReceived event to receive messages from server.
                client.MessageReceived += Client_MessageReceived;
                client.Connected       += Client_Connected;
                client.Disconnected    += Client_Disconnected;
                client.Connect();                 //Connect to the server

                var messageText = "连接服务端成功!";     //Get a message from user
                //Send message to the server
                client.SendMessage(new ScsTextMessage(messageText, "q1"));

                //client.Disconnect(); //Close connection to server
            }
            catch (Exception)
            {
                client.Dispose();
                MessageBox.Show("连接异常!");
            }
        }
Ejemplo n.º 22
0
        private void ConnectAsync()
        {
            while (true)
            {
                try
                {
                    if (_tcpClient == null)
                    {
                        _tcpClient = ScsClientFactory.CreateClient(new ScsTcpEndPoint(Config.PartnerIpAddress, Config.PartnerPort));
                        _tcpClient.WireProtocol = new HostProtocol();
                    }
                    if (_tcpClient.CommunicationState == CommunicationStates.Disconnected)
                    {
                        _coreSvc.Disconnect();
                        _log.Warn("Connecting to Partner...");
                        _tcpClient.Connected       -= Connected;
                        _tcpClient.Disconnected    -= Disconnected;
                        _tcpClient.MessageReceived -= OnMessageReceived;
                        _tcpClient.MessageSent     -= MessageSent;

                        _tcpClient.Connected       += Connected;
                        _tcpClient.Disconnected    += Disconnected;
                        _tcpClient.MessageReceived += OnMessageReceived;
                        _tcpClient.MessageSent     += MessageSent;
                        _tcpClient.Connect();
                    }
                    else if (_tcpClient.CommunicationState == CommunicationStates.Connected)
                    {
                        break;
                    }
                }
                catch (Exception ex)
                {
                    _log.Error(ex.Message);
                    Close();
                }
            }
        }
Ejemplo n.º 23
0
        public virtual void Dispose()
        {
            Helper.stop_timer(ref _1s_timer, "1s timer");

            try { _client.Disconnect(); }
            catch { }
            _client = null;
        }
Ejemplo n.º 24
0
 private void Init()
 {
     _cjIp   = Settings.Default.CjIP;
     _cjPort = Settings.Default.CjPort;
     Client  = ScsClientFactory.CreateClient(new ScsTcpEndPoint(CjIP, CjPort));
 }
Ejemplo n.º 25
0
        public virtual bool Connect(string remote_ip, int remote_port, int timeout=10000)
        {
            try
            {
                this.ServerIp = remote_ip;
                this.ServerPort = remote_port;

                EzWireProtocol protocol = new EzWireProtocol();
                protocol.DataReceived += protocol_DataReceived;//接收到数据,但不一定是message

                _client = ScsClientFactory.CreateClient(new ScsTcpEndPoint(remote_ip, remote_port));
                _client.WireProtocol = protocol;
                _client.Connected += client_Connected;
                _client.Disconnected += client_Disconnected;
                _client.MessageReceived += client_MessageReceived;
                _client.ConnectTimeout = timeout;
                _client.Connect();

                this._remain_life_number = this.DefaultLifeNumber;

                Helper.start_timer(ref _1s_timer, "1s timer", 1000, _1s_timer_Elapsed);
            }
            catch (Exception ex)
            {
                EzLogger.GlobalLogger.warning(string.Format("{0}{2}{1}{2}",
                    ex.Message, ex.StackTrace, Environment.NewLine));

                Dispose();

                return false;
            }
            return true;
        }
Ejemplo n.º 26
0
 public ClientSender(IScsClient client, RequestReplyMessenger <IScsClient> clientRequestReply)
 {
     _clientUtility = new ConnectionUtility(client, clientRequestReply);
 }
Ejemplo n.º 27
0
 private void Init()
 {
     _spIp   = Settings.Default.SpIP;
     _spPort = Settings.Default.SpPort;
     Client  = ScsClientFactory.CreateClient(new ScsTcpEndPoint(SpIP, SpPort));
 }