Ejemplo n.º 1
0
        /// <summary>
        /// Notify connection listeners.
        /// </summary>
        /// <param name="link">The link.</param>
        /// <param name="hasOpened">Is a connection open?</param>
        public void NotifyListenersConnections(IndicatorLink link, bool hasOpened)
        {
            Object[] list = _listeners.ToArray();

            foreach (object t in list)
            {
                var listener = (IIndicatorConnectionListener)t;
                listener.NotifyConnections(link, hasOpened);
            }
        }
Ejemplo n.º 2
0
 public void NotifyConnections(IndicatorLink link, bool hasOpened)
 {
     if (hasOpened)
     {
         Console.WriteLine("Connection from " + link.ClientSocket.RemoteEndPoint.ToString() + " established.");
     }
     else if (!hasOpened)
     {
         Console.WriteLine("Connection from " + link.ClientSocket.RemoteEndPoint.ToString() + " terminated.");
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Background thread.
        /// </summary>
        public void Run()
        {
            try
            {
                _running = true;
                _listenSocket.Listen(5);
                while (_running)
                {
                    try
                    {
                        EncogLogging.Log(EncogLogging.LevelDebug, "Begin listen");
                        Socket connectionSocket = _listenSocket.Accept();
                        EncogLogging.Log(EncogLogging.LevelDebug, "Connection from: " + connectionSocket.RemoteEndPoint);
                        var link = new IndicatorLink(this, connectionSocket);
                        NotifyListenersConnections(link, true);
                        var hc = new HandleClient(this, link);
                        _connections.Add(hc);
                        var t = new Thread(hc.Run);
                        t.Start();
                    }
                    catch (SocketException)
                    {
                        // just accept timing out
                        Thread.Sleep(100);
                    }
                    catch (IOException ex)
                    {
                        throw new IndicatorError(ex);
                    }
                }

                try
                {
                    _listenSocket.Close();
                }
                catch (IOException ex)
                {
                    throw new IndicatorError(ex);
                }
            }
            finally
            {
                _running = false;
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Construct a client handler. 
 /// </summary>
 /// <param name="s">The indicator server.</param>
 /// <param name="l">The indicator link.</param>
 public HandleClient(IndicatorServer s, IndicatorLink l)
 {
     RemoteType = "Unknown";
     Link = l;
     _server = s;
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Notify that this indicator is now connected.  This is called
 /// once, at the beginning of a connection.  Indicators are not
 /// reused.  
 /// </summary>
 /// <param name="theLink">The link.</param>
 public void NotifyConnect(IndicatorLink theLink)
 {
     this.link = theLink;
     if (this.ErrorMessage != null)
     {
         String[] args = { this.ErrorMessage };
         this.Link.WritePacket(IndicatorLink.PACKET_ERROR, args);
     }
     else
     {
         this.link.InitConnection(this.dataRequested, this.blocking);
     }
 }
        /// <summary>
        /// Background thread.
        /// </summary>
        public void Run()
        {
            try
            {
                _running = true;
                _listenSocket.Listen(5);
                while (_running)
                {
                    try
                    {
                        EncogLogging.Log(EncogLogging.LevelDebug, "Begin listen");
                        Socket connectionSocket = _listenSocket.Accept();
                        EncogLogging.Log(EncogLogging.LevelDebug, "Connection from: " + connectionSocket.RemoteEndPoint);
                        var link = new IndicatorLink(this, connectionSocket);
                        NotifyListenersConnections(link, true);
                        var hc = new HandleClient(this, link);
                        _connections.Add(hc);
                        var t = new Thread(hc.Run);
                        t.Start();
                    }
                    catch (SocketException)
                    {
                        // just accept timing out
                        Thread.Sleep(100);
                    }
                    catch (IOException ex)
                    {
                        throw new IndicatorError(ex);
                    }
                }

                try
                {
                    _listenSocket.Close();
                }
                catch (IOException ex)
                {
                    throw new IndicatorError(ex);
                }
            }
            finally
            {
                _running = false;
            }
        }
        /// <summary>
        /// Notify connection listeners.
        /// </summary>
        /// <param name="link">The link.</param>
        /// <param name="hasOpened">Is a connection open?</param>
        public void NotifyListenersConnections(IndicatorLink link, bool hasOpened)
        {
            Object[] list = _listeners.ToArray();

            foreach (object t in list)
            {
                var listener = (IIndicatorConnectionListener) t;
                listener.NotifyConnections(link, hasOpened);
            }
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Construct a client handler.
 /// </summary>
 /// <param name="s">The indicator server.</param>
 /// <param name="l">The indicator link.</param>
 public HandleClient(IndicatorServer s, IndicatorLink l)
 {
     RemoteType = "Unknown";
     Link       = l;
     _server    = s;
 }
 /// <summary>
 /// Notify that this indicator is now connected.  This is called
 /// once, at the beginning of a connection.  Indicators are not
 /// reused.  
 /// </summary>
 /// <param name="theLink">The link.</param>
 public void NotifyConnect(IndicatorLink theLink)
 {
     _link = theLink;
     if (ErrorMessage != null)
     {
         String[] args = {ErrorMessage};
         Link.WritePacket(IndicatorLink.PacketError, args);
     }
     else
     {
         _link.InitConnection(_dataRequested, _blocking);
     }
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Background thread.
        /// </summary>
        public void run()
        {
            this.running = true;
            while (this.running)
            {
                try
                {
                    EncogLogging.Log(EncogLogging.LogLevel.Debug, "Begin listen");
                    Socket connectionSocket = listenSocket.Accept();
                    EncogLogging.Log(EncogLogging.LogLevel.Debug, "Connection from: " + connectionSocket.RemoteEndPoint.ToString());
                    IndicatorLink link = new IndicatorLink(this, connectionSocket);
                    NotifyListenersConnections(link, true);
                    HandleClient hc = new HandleClient(this, link);
                    this.connections.Add(hc);
                    Thread t = new Thread(new ThreadStart(hc.run));
                    t.Start();
                }
                catch (SocketException ex)
                {
                    // ignore
                }
                catch (IOException ex)
                {
                    throw new IndicatorError(ex);
                }
            }

            try
            {
                this.listenSocket.Close();
            }
            catch (IOException ex)
            {
                throw new IndicatorError(ex);
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Notify connection listeners.
        /// </summary>
        /// <param name="link">The link.</param>
        /// <param name="hasOpened">Is a connection open?</param>
        public void NotifyListenersConnections(IndicatorLink link, bool hasOpened)
        {
            Object[] list = this.listeners.ToArray();

            for (int i = 0; i < list.Length; i++)
            {
                IIndicatorConnectionListener listener = (IIndicatorConnectionListener)list[i];
                listener.NotifyConnections(link, hasOpened);
            }
        }