CentralMine.NET.Client.SendClientInfo C# (CSharp) Method

SendClientInfo() public method

public SendClientInfo ( string info ) : void
info string
return void
        public void SendClientInfo(string info)
        {
            MemoryStream stream = new MemoryStream();
            BinaryWriter bw = new BinaryWriter(stream);
            bw.Write((byte)8);
            bw.Write(System.Text.Encoding.ASCII.GetBytes(info));
            SendPacket(stream.ToArray());
            bw.Close();
        }

Usage Example

        void Update()
        {
            while (true)
            {
                double oldHashrate = mHashrate;
                mHashrate = 0;
                if (mBlock == null || mUpstream.NewBlockReady() || mBlock.mHashMan.IsComplete() || mBlock.mHashMan.IsExpired())
                {
                    // Start work on a new block
                    BeginBlock();
                }

                Client clientThatWantsInfo = null;

                if (mClientListMutex.WaitOne(1))
                {
                    int clientsOnline = mClients.Count;
                    foreach (Client c in mClients)
                    {
                        bool stillAlive = c.Update();
                        if (!stillAlive)
                        {
                            if (c.mCurrentBlock != null)
                            {
                                c.mCurrentBlock.mHashMan.FreeBlock(c.mHashBlock);
                            }
                            mClients.Remove(c);
                            break;
                        }
                        mHashrate += c.mHashrate;

                        if (c.mState == Client.State.Busy && c.mCurrentBlock != mBlock)
                        {
                            c.StopWork();
                        }

                        if (c.mState == Client.State.Ready)
                        {
                            AssignWork(c);
                        }

                        if (c.mStatusClient)
                        {
                            c.SendStatus(clientsOnline, oldHashrate);
                        }

                        if (c.mClientInfoRequested && clientThatWantsInfo == null)
                        {
                            clientThatWantsInfo    = c;
                            c.mClientInfoRequested = false;
                        }
                    }

                    if (clientThatWantsInfo != null)
                    {
                        string info = "{\"clients\":[";
                        foreach (Client c in mClients)
                        {
                            info += c.ToJSON() + ",";
                        }
                        info  = info.Substring(0, info.Length - 1);
                        info += "]}";
                        clientThatWantsInfo.SendClientInfo(info);
                    }

                    mClientListMutex.ReleaseMutex();
                    Thread.Sleep(50);
                }
                else
                {
                    Thread.Sleep(1);
                }

                if (mDumpClients)
                {
                    FileStream   file = new FileStream("clients.txt", FileMode.Create);
                    StreamWriter sw   = new StreamWriter(file);

                    mClientListMutex.WaitOne();
                    foreach (Client c in mClients)
                    {
                        string str = c.ToString();
                        sw.WriteLine(str);
                    }
                    mClientListMutex.ReleaseMutex();

                    sw.Close();
                    mDumpClients = false;
                }
            }
        }