Esempio n. 1
0
        private void ThreadTCPClient()
        {
            CTCPClient cl = new CTCPClient("127.0.0.1", 81, modelMarket);



            while (!cl.ConnectToServer())
            {
                Thread.Sleep(1000);
            }
        }
Esempio n. 2
0
        protected void AddTCPCleintAndDataReciever(int connId)
        {
            AddDataReciever(connId);

            if (_dictTCPClients.ContainsKey(connId))
            {
                throw new Exception("TCP client is already exist");
            }


            CTCPClient tcpClient = new CTCPClient(_serverConfig.Servers[connId].IP, (int)_serverConfig.Servers[connId].Port, /*dataReciever*/ GetTCPClientUser(connId));

            _dictTCPClients[connId] = tcpClient;
        }
Esempio n. 3
0
        /// <summary>
        /// Creates message of specificated format (header, body) and writes message to tcpClient.
        ///
        ///
        ///
        /// Call from:
        /// 1) Internal class methods
        /// 2) From MarketViewModel
        /// </summary>
        /// <param name="conId"></param>
        /// <param name="ob"></param>
        /// <param name="ev"></param>
        public void SendDataToServer(int conId, object ob, enmTradingEvent ev)
        {
            CTCPClient tcpClient = null;

            if (GetTCPClient(conId, out tcpClient))
            {
                byte[] arrHeader = _messenger.GenBinaryMessageHeader((byte)ev);
                byte[] arrBody   = CUtilProto.SerializeProto(ob);

                byte[] arrMsg = new byte[arrHeader.Length + arrBody.Length];

                Buffer.BlockCopy(arrHeader, 0, arrMsg, 0, arrHeader.Length);
                Buffer.BlockCopy(arrBody, 0, arrMsg, arrHeader.Length, arrBody.Length);

                tcpClient.WriteMessage(arrMsg);
            }
        }
Esempio n. 4
0
        public TestTcpClient()
        {
            _log = new CLogger("TestTcpClient");

            _log.Log("============================================================================================================");
            _tcpClient = new CTCPClient("83.146.113.81", 81, _tcpClientStub);


            while (!_tcpClient.ConnectToServer())
            {
                Thread.Sleep(1000);
            }



            (new Thread(ThreadWrite)).Start();

            while (true)
            {
                Thread.Sleep(100);
            }
        }
Esempio n. 5
0
 protected bool GetTCPClient(int conId, out CTCPClient tcpClient)
 {
     return(_dictTCPClients.TryGetValue(conId, out tcpClient));
 }
Esempio n. 6
0
        private void ThreadGetDataScales()
        {
            DataBarCode.CLog.WriteInfo("DataScales.cs", "Start Thread Get DataScales");
            CTCPClient _client = new CTCPClient(set.DataScalesServerIp, set.DataScalesServerPort);

            while (GetDataScales)
            {
                try
                {
                    if (SelectedScales != null)
                    {
                        string[] data = _client.getData(SelectedScales);

                        buttonFix.BeginInvoke(new Action(() =>
                        {
                            buttonFix.Enabled = true;
                        }));


                        if (data != null)
                        {
                            string Weigth = data[2];
                            bool   Stabl  = bool.Parse(data[4]);
                            //CLog.WriteInfo("DataScales.cs", "Пришел вес: " + Weigth + " ;Стаб: " + Stabl.ToString());

                            labelWeigth.BeginInvoke(new Action(() =>
                            {
                                labelWeigth.Text = Weigth;
                                if (Stabl)
                                {
                                    labelWeigth.ForeColor = Color.White;
                                }
                                else
                                {
                                    labelWeigth.ForeColor = Color.Tomato;
                                }
                            }));
                        }
                    }
                }

                catch (SocketException exp)
                {
                    CLog.WriteException("DataScales.cs", "ThreadGetDataScales_SocketException", exp.Message);

                    labelWeigth.BeginInvoke(new Action(() =>
                    {
                        labelWeigth.Text      = "Нет связи";
                        labelWeigth.ForeColor = Color.Tomato;
                    }));

                    buttonFix.BeginInvoke(new Action(() =>
                    {
                        buttonFix.Enabled = false;
                    }));
                    Thread.Sleep(set.DataScalesServerTime * 5);
                }

                catch (Exception exp)
                {
                    CLog.WriteException("DataScales.cs", "ThreadGetDataScales", exp.Message);

                    labelWeigth.BeginInvoke(new Action(() =>
                    {
                        labelWeigth.Text      = "Ошибка";
                        labelWeigth.ForeColor = Color.Tomato;
                    }));

                    buttonFix.BeginInvoke(new Action(() =>
                    {
                        buttonFix.Enabled = false;
                    }));
                }
                Thread.Sleep(set.DataScalesServerTime);
            }
            CLog.WriteInfo("DataScales.cs", "Stop Thread Get DataScales");
        }