CentralMine.NET.Client.Update C# (CSharp) Méthode

Update() public méthode

public Update ( ) : bool
Résultat bool
        public bool Update()
        {
            if (!mClient.Connected)
                return false;

            if (mHashBlock != null)
            {
                TimeSpan s = DateTime.Now - mWorkSent;
                if (s.TotalSeconds > 120)
                {
                    // This work took to long, just close the connection and force this client to reconnect
                    IPEndPoint remoteIP = mClient.Client.RemoteEndPoint as IPEndPoint;
                    Console.WriteLine(remoteIP.ToString() + " took more than 120 seconds for work");
                    mClient.Close();
                    return false;
                }
            }

            if (mState != State.New)
            {
                try
                {
                    TimeSpan span = DateTime.Now - mLastSeen;
                    if (span.TotalSeconds > 5)
                    {
                        // Send ping
                        byte[] ping = { 5 };
                        SendPacket(ping);
                    }
                }
                catch (Exception)
                {
                    return false;
                }
            }
            else
            {
                TimeSpan span = DateTime.Now - mLastSeen;
                if (span.TotalSeconds > 5)
                {
                    // No identity packet, kill the connection
                    mClient.Close();
                    return false;
                }
            }

            try
            {
                NetworkStream stream = mClient.GetStream();
                if (stream.DataAvailable)
                {
                    mLastSeen = DateTime.Now;
                    int command = stream.ReadByte();
                    switch (command)
                    {
                        case 1:
                            ProcessIdentity(stream);
                            break;
                        case 2:
                            ProcessWorkComplete(stream);
                            break;
                        case 5: // Ping
                            break;
                        case 7:
                            mClientInfoRequested = true;
                            break;
                        case 71:
                            ProcessWebsocketConnect(stream);
                            break;
                        case 130:
                            ProcessWebsocketPacket(stream);
                            break;
                        case 136:
                            // websocket close?
                            mClient.Close();
                            return false;
                        default:
                            byte[] temp = new byte[16 * 1024];
                            int read = stream.Read(temp, 0, (int)temp.Length);
                            Console.WriteLine("Read unknown bytes(" + (read + 1) + ")");
                            /*
                            Console.Write((char)command);
                            for (int i = 0; i < read; i++)
                            {
                                Console.Write((char)temp[i]);
                            }
                            Console.WriteLine("");
                            */
                            break;
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return false;
            }

            return true; // still alive
        }