Ejemplo n.º 1
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 (Exception ex)
            {
                CloseSocket(newsocket);
                //this.Soft.ErrorManager.Process(ex);
                log.Error(ex);
                return;
            }

            this._newCommuniPort = scp;

            //this.Soft.CommuniPortManager.Add(scp);
            OnNewCommuniPortEvent();
        }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        override public ICommuniPort Create()
        {
            if (!CanCreate)
            {
                throw new InvalidOperationException(string.Format("Cannot create communi port with '{0}'", this));
            }

            this.LastCreateDateTime = DateTime.Now;

            SocketCommuniPort sckCP = null;

            Socket socket = new Socket(AddressFamily.InterNetwork,
                                       SocketType.Stream, ProtocolType.Tcp);

            socket.Connect(this.RemoteIPAddress, this.RemotePort);
            sckCP = new SocketCommuniPort(socket);
            return(sckCP);


            //try
            //{
            //    socket.Connect(this.RemoteIPAddress, this.RemotePort);
            //    sckCP = new SocketCommuniPort(socket);
            //}
            //catch (SocketException sckEx)
            //{
            //    log.Error("Create socket fail.\r\n" + sckEx);
            //}
            //catch (Exception ex)
            //{
            //    log.Error("Create socket fail.\r\n" + ex);
            //    throw;
            //}
        }
Ejemplo n.º 3
0
        override public bool IsMatch(ICommuniPort cp)
        {
            bool r = false;
            SocketCommuniPort scp = cp as SocketCommuniPort;

            if (scp != null)
            {
                r = this.LocalPort == ((IPEndPoint)scp.LocalEndPoint).Port;
            }
            return(r);
        }
Ejemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cp"></param>
        /// <returns></returns>
        override public bool IsMatch(ICommuniPort cp)
        {
            if (cp == null)
            {
                return(false);
            }

            bool r = false;

            if (cp is SocketCommuniPort)
            {
                SocketCommuniPort scp = cp as SocketCommuniPort;

                EndPoint   ep        = scp.RemoteEndPoint;
                IPEndPoint ipep      = ep as IPEndPoint;
                IPAddress  ipAddress = ipep.Address;

                r = ipAddress.Equals(RemoteIPAddress);
            }
            return(r);
        }