Exemplo n.º 1
0
 public RemoteJobConsumer(int maxNumOfConnections)
 {
     mMaxNumOfConnections = maxNumOfConnections;
     mConnectionList = new Dictionary<string, ConnectionInfo>();
     mListLocker = new object();
     mIsRunning = false;
     mApi = null;
 }
Exemplo n.º 2
0
        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();
        }
Exemplo n.º 3
0
 public NetworkJobListener()
 {
     mIsListening = false;
     mListener = null;
     mApi = null;
 }
Exemplo n.º 4
0
        /// <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;
        }
Exemplo n.º 5
0
        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;
        }