Example #1
0
        private void UnreginsterEvents(CommuniPort cp)
        {
            SocketCommuniPort sckcp = cp as SocketCommuniPort;

            sckcp.ClosedEvent   -= new EventHandler(sckcp_ClosedEvent);
            sckcp.ReceivedEvent -= new EventHandler(sckcp_ReceivedEvent);
        }
Example #2
0
 public bool Remove(CommuniPort cp)
 {
     if (this.CommuniPorts.Remove(cp))
     {
         UnreginsterEvents(cp);
         return(true);
     }
     return(false);
 }
Example #3
0
 //删除集合中已经存在的,相同远程地址的SocketCommuniPort
 private void BeforeAdd(CommuniPort cp)
 {
     if (cp is SocketCommuniPort)
     {
         SocketCommuniPort scp = cp as SocketCommuniPort;
         for (int i = this.CommuniPorts.Count - 1; i >= 0; i--)
         {
             CommuniPort cp2 = this.CommuniPorts[i];
             if (cp2 is SocketCommuniPort)
             {
                 SocketCommuniPort scp2  = cp2 as SocketCommuniPort;
                 IPEndPoint        ipep  = scp.Socket.RemoteEndPoint as IPEndPoint;
                 IPEndPoint        ipep2 = scp2.Socket.RemoteEndPoint as IPEndPoint;
                 if (ipep.Address.Equals(ipep2.Address))
                 {
                     Remove(cp2);
                 }
             }
         }
     }
 }
Example #4
0
        //新建连接事件
        private void RegisterEvents(CommuniPort cp)
        {
            SocketCommuniPort sckcp = cp as SocketCommuniPort;

            if (sckcp != null)
            {
                sckcp.ClosedEvent   += new EventHandler(sckcp_ClosedEvent);
                sckcp.ReceivedEvent += new EventHandler(sckcp_ReceivedEvent);

                string ip = ((IPEndPoint)sckcp.RemoteEndPoint).Address.ToString();
                for (int i = 0; i < Gprs._GprsList.Length; i++)
                {
                    if (Gprs._GprsList[i]._ip == ip)
                    {
                        Gprs._GprsList[i]._socket = sckcp.Socket;
                        Gprs._GprsList[i]._Iscon  = true;
                        Gprs._GprsList[i]._Isbusy = false;
                        //测试
                        Gprs._GprsList[i]._activate = true;
                        break;
                    }
                }
            }
        }
Example #5
0
 public void Add(CommuniPort cp)
 {
     BeforeAdd(cp);
     this.CommuniPorts.Add(cp);
     RegisterEvents(cp);
 }