Exemplo n.º 1
0
        /// <summary>
        /// FD event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void scp_ReceivedEvent(object sender, EventArgs e)
        {
            SocketCommuniPort sckcp = sender as SocketCommuniPort;

            byte[] bs = sckcp.Read();
            this.CommuniSoft.FDManager.Process(sckcp, bs);
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        private void UnreginsterEvents(CommuniPort cp)
        {
            SocketCommuniPort sckcp = cp as SocketCommuniPort;

            sckcp.ClosedEvent   -= new EventHandler(sckcp_ClosedEvent);
            sckcp.ReceivedEvent -= new EventHandler(sckcp_ReceivedEvent);
        }
Exemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void item_ConnectedEvent(object sender, EventArgs e)
        {
            SocketListener sl        = sender as SocketListener;
            Socket         newsocket = sl.NewSocket;

            if (newsocket == null)
            {
                return;
            }
            if (!newsocket.Connected)
            {
                return;
            }

            SocketCommuniPort scp = null;

            try
            {
                scp = new SocketCommuniPort(newsocket);
            }
            catch
            {
                CloseSocket(newsocket);
                return;
            }

            scp.ReceivedEvent += new EventHandler(scp_ReceivedEvent);
            bool b = StationCommuniPortBinder.Bind(
                this._communiSoft.HardwareManager.Stations, scp);

            if (!b)
            {
                this._communiSoft.CommuniPortManager.Add(scp);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public SocketCommuniPort CreateSocketCommuniPort(Socket socket )
        {
            if (socket == null)
                throw new ArgumentNullException("socket");

            SocketCommuniPort scp = new SocketCommuniPort(socket);
            return scp;
        }
Exemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void sckcp_ReceivedEvent(object sender, EventArgs e)
        {
            SocketCommuniPort sckcp = sender as SocketCommuniPort;

            byte[] bytes = sckcp.Read();
            CommuniPortReceivedEventArgs e2 = new CommuniPortReceivedEventArgs(sckcp, bytes);

            OnCommuniPortReceived(e2);
        }
Exemplo n.º 6
0
        /// <summary>
        ///
        /// </summary>
        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);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public SocketCommuniPort CreateSocketCommuniPort(Socket socket)
        {
            if (socket == null)
            {
                throw new ArgumentNullException("socket");
            }

            SocketCommuniPort scp = new SocketCommuniPort(socket);

            return(scp);
        }
Exemplo n.º 8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="stations"></param>
 /// <param name="scp"></param>
 internal static bool Bind(StationCollection stations, SocketCommuniPort scp)
 {
     foreach (Station st in stations)
     {
         if (scp.Match(st.CommuniType))
         {
             ClearBind(st);
             return(Bind(st, scp));
         }
     }
     return(false);
 }
Exemplo n.º 9
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="stations"></param>
 /// <param name="scp"></param>
 internal static bool Bind(StationCollection stations, SocketCommuniPort scp)
 {
     foreach (Station st in stations)
     {
         if (scp.Match(st.CommuniType))
         {
             ClearBind(st);
             return Bind(st, scp);
         }
     }
     return false;
 }
Exemplo n.º 10
0
 /// <summary>
 /// 删除集合中已经存在的,相同远程地址的SocketCommuniPort
 /// </summary>
 /// <param name="cp"></param>
 private void BeforeAdd(CommuniPort cp)
 {
     // TODO: allow same ip address option
     //
     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.RemoteEndPoint as IPEndPoint;
                 IPEndPoint        ipep2 = scp2.RemoteEndPoint as IPEndPoint;
                 if (ipep.Address.Equals(ipep2.Address))
                 {
                     Remove(cp2);
                 }
             }
         }
     }
 }
Exemplo n.º 11
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void item_ConnectedEvent(object sender, EventArgs e)
        {
            SocketListener sl = sender as SocketListener;
            Socket newsocket = sl.NewSocket;
            if( newsocket == null)
                return;
            if (!newsocket.Connected)
            {
                return;
            }

            SocketCommuniPort scp = null;
            try
            {
                scp = new SocketCommuniPort(newsocket);
            }
            catch
            {
                CloseSocket(newsocket);
                return;
            }

            scp.ReceivedEvent += new EventHandler(scp_ReceivedEvent);
            bool b = StationCommuniPortBinder.Bind(
                this._communiSoft.HardwareManager.Stations, scp);

            if (!b)
            {
                this._communiSoft.CommuniPortManager.Add(scp);
            }
        }
Exemplo n.º 12
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="socketCP"></param>
 public SocketCommuniPortConnectedState(SocketCommuniPort socketCP)
     : base(socketCP)
 {
 }