public RemoteJobConsumer(int maxNumOfConnections)
 {
     mMaxNumOfConnections = maxNumOfConnections;
     mConnectionList = new Dictionary<string, ConnectionInfo>();
     mListLocker = new object();
     mIsRunning = false;
     mApi = null;
 }
        public void Connect(string serverAddress, ClientInfo selfInfo)
        {
            Uri serverUrl = new Uri("http://" + serverAddress, UriKind.Absolute);
            mApi = new ServerApi(serverUrl);
            mSelfInfo = selfInfo;

            // Start Keep Alive loop in a different thread.
            // This will update the list of connected smashers and get more from the server if necessary
            mIsRunning = true;
            Thread updateThread = new Thread(new ThreadStart(() => {
                Update();
            }));
            updateThread.Start();
        }
 public NetworkJobListener()
 {
     mIsListening = false;
     mListener = null;
     mApi = null;
 }
        /// <summary>
        /// Listen the specified serverAddress, listenerPort and clientVersion.
        /// THIS BLOCKS THE THREAD! Run in a different thread if you don't want to block!
        /// </summary>
        public bool Listen(string serverAddress, ClientInfo listenerInfo)
        {
            if (mIsListening)
            {
                throw new InvalidOperationException("Sorry, you can't listen with the same listener twice...");
            }

            Uri serverUrl = new Uri("http://" + serverAddress, UriKind.Absolute);
            mApi = new ServerApi(serverUrl);
            mListenerInfo = listenerInfo;

            if (!mApi.AddSmasher(mListenerInfo))
                return false;

            // Start listening
            mIsListening = true;
            UpdateLoop(SmasherAddressUtil.GetSmasherEndPoint(mListenerInfo.Address));

            return true;
        }
        public void Stop()
        {
            if (mApi != null)
            {
                mApi.RemoveSmasher(mListenerInfo);
                mApi = null;
            }

            // This stops listening
            if (mListener != null && mListener.Connected)
            {
                // We don't want to use Shutdown here!
                mListener.Close(500);
                mListener = null;
            }

            // Do this in the end
            mIsListening = false;
        }