Ejemplo n.º 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);
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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();
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 6
0
        /// <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);
        }
Ejemplo n.º 7
0
 void newMessageEventFun(tcpDataCommunication comm, stringMsg msg)
 {
 }
Ejemplo n.º 8
0
 public void connectionDisconnectionEventFun(tcpDataCommunication comm)
 {
     removeTcp(comm);
 }