Exemple #1
0
 public int Connect(System.Net.IPEndPoint ip)
 {
     System.Net.Sockets.TcpClient tcp = new System.Net.Sockets.TcpClient();
     tcp.Connect(ip);
     tcpComm = new tcpDataCommunication(tcp);
     return(0);
 }
Exemple #2
0
        /// <summary>
        /// 消息接收事件处理程序
        /// </summary>
        /// <param name="tcpComm"></param>
        /// <param name="ble"></param>
        void newBlemessageEventFun(tcpDataCommunication tcpComm, BLE.BLEData ble)
        {
            string    s1 = ble.ToString();
            stringMsg m2 = stringMsg.jsonToModel(s1);

            newMessageEvent?.Invoke(tcpComm, m2);
        }
Exemple #3
0
        /// <summary>
        /// 从集合移除连接
        /// </summary>
        /// <param name="tcp"></param>
        public void removeTcp(tcpDataCommunication tcp)
        {
            tcpDataCommunication t;

            if (this.tcpList.TryRemove(tcp.tcpClientId, out t))
            {
                removeTcpEvent?.Invoke(tcp);
            }
        }
Exemple #4
0
        /// <summary>
        /// 停止现在正在运行的连接
        /// </summary>
        public void stop()
        {
            List <string> keyList = tcpList.Keys.ToList();

            foreach (var item in keyList)
            {
                tcpDataCommunication t = tcpList[item];
                removeTcp(t);
                t.stop();
            }
        }
Exemple #5
0
        /// <summary>
        /// 添加连接到集合
        /// </summary>
        /// <param name="tcp"></param>
        public tcpDataCommunication addTcp(TcpClient tcp)
        {
            tcpDataCommunication tcpCommunication = new tcpDataCommunication(tcp);

            tcpCommunication.newBleMessageEvent += newBlemessageEventFun;

            if (this.tcpList.TryAdd(tcpCommunication.tcpClientId, tcpCommunication))
            {
                addTcpEvent?.Invoke(tcpCommunication);
            }
            return(tcpCommunication);
        }
        /// <summary>
        /// 消息接收事件处理程序
        /// </summary>
        /// <param name="tcpComm"></param>
        /// <param name="ble"></param>
        void newBlemessageEventFun(tcpDataCommunication tcpComm, BLE.BLEData ble)
        {
            string s1 = "";

            if (ble.command == BLEcommand.t11)
            {
                s1 = ble.ToString();
            }
            else if (ble.command == BLEcommand.t12)
            {
                s1 = ((BLE.bleClass.t12)ble).ReceiveFullMsg;
            }
            stringMsg m2 = stringMsg.jsonToModel(s1);

            newMessageEvent?.Invoke(tcpComm, m2);
        }
Exemple #7
0
 void newMessageEventFun(tcpDataCommunication comm, stringMsg msg)
 {
 }
 public void connectionDisconnectionEventFun(tcpDataCommunication comm)
 {
     removeTcp(comm);
 }