예제 #1
0
        private void button5_Click(object sender, EventArgs e)
        {
            BLE.stringMsg m1 = new BLE.stringMsg();
            m1.name = BLE.msgEnum.liaotian;
            m1.value.Add("value", this.richTextBox2.Text);

            tcpClient1.tcpComm.sendData(m1);
        }
예제 #2
0
        /////要测试的几个问题,可不可以同时进行读写.可不可以一个tcp类,get多个流进行读写.多个流是不是一个实例.,可不可以多线程读写.
        ////测试结果,tcp不管调用多少次GetStream,获取到的都是同一个stream对象. 一个流可以同时进行读取和写入(可能是有2个缓冲区).
        ////连接断开后,设备会不会自动重新连接服务器.


        void xintiao(object o)
        {
            if (this.waitSendList.Count < 1 && this.currentSendBleData == null)
            {
                BLE.stringMsg s1 = new BLE.stringMsg();
                s1.name = BLE.msgEnum.xintiao;
                this.addSendBle(s1);
            }
        }
예제 #3
0
        //群发消息
        private void button6_Click(object sender, EventArgs e)
        {
            ConcurrentDictionary <string, tcpDataCommunication> tcpList = tcpConnection.tcpList;

            foreach (KeyValuePair <string, tcpDataCommunication> tcp in tcpList)
            {
                tcpDataCommunication tcpComm = tcp.Value;
                BLE.stringMsg        m1      = new BLE.stringMsg();
                m1.name = BLE.msgEnum.liaotian;
                m1.value.Add("groupSending", this.richTextBox1.Text);
                tcpComm.sendData(m1);
            }
            this.richTextBox1.Text = String.Empty;
        }
예제 #4
0
        void denglu(tcpDataCommunication tcpComm, stringMsg msg)
        {
            string account = msg.value["account"];
            string pwd     = msg.value["pwd"];
            bool   bl      = user.Login(account, pwd);

            BLE.stringMsg m1 = new BLE.stringMsg();
            m1.name = BLE.msgEnum.dengru;
            m1.value.Add("return", bl.ToString());



            tcpComm.sendData(m1);
        }
예제 #5
0
        //给服务端发消息
        private void button5_Click(object sender, EventArgs e)
        {
            BLE.stringMsg m1 = new BLE.stringMsg();
            m1.name = BLE.msgEnum.liaotian;
            m1.value.Add("value", this.richTextBox2.Text);

            //      zTcpClient1.tcpComm.sendData(m1);

            //if (zTcpClient1.tcpComm.tcpClient1.Connected)
            //{

            //}

            zTcpClient1.tcpComm.addSendBle(m1);
            this.richTextBox2.Text = "";
        }
예제 #6
0
        //指定用户发送消息
        private void button5_Click_1(object sender, EventArgs e)
        {
            DataGridViewSelectedRowCollection rows = this.dataGridView1.SelectedRows;

            if (rows.Count > 0)
            {
                foreach (DataGridViewRow item in rows)
                {
                    DataGridViewRow itemx   = item;
                    string          address = item.Cells[2].Value.ToString();

                    ConcurrentDictionary <string, tcpDataCommunication> tcpList = tcpConnection.tcpList;
                    List <string> keyList = tcpList.Keys.ToList();
                    string        key     = "";
                    foreach (string keyAddress in keyList)
                    {
                        string k = keyAddress.Substring(keyAddress.LastIndexOf("&") + 1, keyAddress.Length - keyAddress.LastIndexOf('&') - 1);
                        if (k.Equals(address))
                        {
                            key = keyAddress;
                        }
                    }
                    tcpDataCommunication tcpComm = tcpList[key];
                    BLE.stringMsg        m1      = new BLE.stringMsg();
                    m1.name = BLE.msgEnum.liaotian;
                    m1.value.Add("singleSending", this.richTextBox1.Text);
                    tcpComm.sendData(m1);
                    //foreach (KeyValuePair<string, tcpDataCommunication> tcp in tcpList)
                    //{
                    //    tcpDataCommunication tcpComm = tcp.Value;



                    //}
                    this.richTextBox1.Text = String.Empty;
                }
            }
            else
            {
                MessageBox.Show("至少选择一个用户");
            }
        }
예제 #7
0
        /// <summary>
        /// 添加发送队列
        /// </summary>
        /// <param name="m1"></param>
        public void addSendBle(BLE.stringMsg m1)
        {
            BLEData ble1;

            if (m1.name == msgEnum.fileUpload)
            {
                string sendFileFullPath = m1.value["sendFileFullPath"];
                string saveFileFullPath = m1.value["saveFileFullPath"];

                BLE.bleClass.t12 t12 = new BLE.bleClass.t12();

                //  t12.sendFileFullPath = sendFileFullPath;

                //  string fileName = System.IO.Path.GetFileName(sendFileFullPath);

                //  ConfigInfo config = user.GetSave();
                //  string reviced = System.IO.Path.Combine(CurrUser.config.Path + "\\" + CurrUser.currUser.ID, fileName);//d:\\
                //stringMsg sm = new stringMsg();
                //sm.name = msgEnum.fileUpload;
                //sm.value.Add("sendFileFullPath", sendFileFullPath);
                //sm.value.Add("saveFileFullPath", saveFileFullPath);

                //   sm.value.Add("fileDirFullPath", CurrUser.config.Path + "\\" + CurrUser.currUser.ID);//文件存储路径


                t12.ReceiveFullMsg = m1.modelToJson();



                ble1 = t12;
            }
            else
            {
                BLE.bleClass.t11 t11 = new BLE.bleClass.t11();

                t11.msg = m1.modelToJson();

                ble1 = t11;
            }

            addSendBle(ble1);
        }
예제 #8
0
        void denglu(tcpDataCommunication tcpComm, stringMsg msg)
        {
            string address = tcpComm.tcpClientId.Split('&')[2];
            string account = msg.value["account"];
            string pwd     = msg.value["pwd"];

            RetUser curr = user.Login(account, pwd);

            BLE.stringMsg m1 = new BLE.stringMsg();
            m1.name = BLE.msgEnum.dengru;
            m1.value.Add("return", curr.Success.ToString());


            if (curr.Success)
            {
                tcpComm.user = curr.User;
                if (Common.UserViewList == null)
                {
                    Common.UserViewList = new List <UserView>();
                }
                Common.UserViewList.Add(new UserView()
                {
                    ID = curr.User.ID, Name = curr.User.Account, Address = address
                });
                BindDataGridView(Common.UserViewList);
                m1.value.Add("ID", curr.User.ID.ToString());

                string jsonCurr = JsonConvert.SerializeObject(curr);
                m1.value.Add("jsonCurr", jsonCurr);

                ConfigInfo config     = user.GetSave();
                string     jsonConfig = JsonConvert.SerializeObject(config);
                m1.value.Add("ConfigInfo", jsonConfig);
            }



            tcpComm.sendData(m1);

            // UserService user = new UserService();
        }
예제 #9
0
        /// <summary>
        /// 发送数据
        /// </summary>
        /// <param name="data"></param>
        public void sendData(BLE.stringMsg m1)
        {
            lock (this)
            {
                try
                {
                    BLE.bleClass.t11 t11 = new BLE.bleClass.t11();

                    t11.msg = m1.modelToJson();

                    sendData(t11);
                }
                catch (ObjectDisposedException ex2)
                {
                    connectionDisconnection();
                }
                catch (IOException ex3)
                {
                    connectionDisconnection();
                }
            }
        }