BoincGuiRpc.Net Tutorial: Managing Distributed Computing via C#
Distributed computing allows developers to harness massive computational power by splitting complex tasks across thousands of volunteer computers. The Berkeley Open Infrastructure for Network Computing (BOINC) is the leading platform for these projects. By using the BoincGuiRpc.Net library, C# developers can programmatically connect to, monitor, and control BOINC clients.
This tutorial demonstrates how to set up BoincGuiRpc.Net, establish a secure connection to a BOINC client, and execute core management commands. Prerequisites
Before diving into the code, ensure your environment meets the following requirements: .NET SDK: Version 6.0 or higher.
BOINC Client: Installed and running on your local machine or an accessible network server.
RPC Password: Found in the gui_rpc_auth.cfg file inside your BOINC data directory. Step 1: Install the Package
To begin, add the BoincGuiRpc.Net NuGet package to your C# project. Run the following command in your .NET CLI or Package Manager Console: dotnet add package BoincGuiRpc.Net Use code with caution. Step 2: Establish a Connection
The BOINC client communicates via a Graphical User Interface Remote Procedure Call (GUI RPC) binded to port 31416 by default. To interact with it, initialize a BoincControl client and authenticate using your RPC password.
using System; using System.Threading.Tasks; using BoincGuiRpc.Net; class Program { static async Task Main(string[] args) { string host = “localhost”; int port = 31416; string password = “your_gui_rpc_auth_password”; // Initialize the BOINC client wrapper var boincClient = new BoincControl(host, port); // Connect and authenticate bool isConnected = await boincClient.ConnectAsync(password); if (isConnected) { Console.WriteLine(“Successfully connected to BOINC client!”); await RunBoincOperations(boincClient); } else { Console.WriteLine(“Connection failed. Check your host, port, and password.”); } } } Use code with caution. Step 3: Fetching Client Information
Once connected, you can retrieve real-time state statistics from the client. This includes project attachments, active computational tasks, and host system details.
static async Task RunBoincOperations(BoincControl client) { // Fetch system state var state = await client.GetStateAsync(); Console.WriteLine(\(" --- Host Info ---"); Console.WriteLine(\)“Operating System: {state.HostInfo.OsName} {state.HostInfo.OsVersion}”); Console.WriteLine(\("CPU Model: {state.HostInfo.CpuModel}"); Console.WriteLine(\)” — Attached Projects —“); foreach (var project in state.Projects) { Console.WriteLine(\("- {project.ProjectName} ({project.MasterUrl})"); } } </code> Use code with caution. Step 4: Managing Active Tasks</p> <p>Monitoring and handling active results (tasks) is crucial for custom dashboards or automation scripts. The following snippet iterates through active tasks to print their current progress and status.</p> <p><code>// Get list of active tasks var results = await client.GetResultsAsync(); Console.WriteLine(\)” — Active Tasks ({results.Count}) —“); foreach (var task in results) { double progressPercent = task.FractionDone100; Console.WriteLine(\("- Task: {task.Name}"); Console.WriteLine(\)” Progress: {progressPercent:F2}%“); Console.WriteLine($” Status: {task.State}“); } Use code with caution. Step 5: Controlling Computational States
BoincGuiRpc.Net allows you to change the global computation state of the client. This feature is perfect for shifting workloads based on scheduling scripts or computer hardware temperature thresholds.
// Pause all BOINC computations temporarily await client.SetCpuModeAsync(RunMode.Never, 0); Console.WriteLine(“Computations suspended.”); // Resume normal computational schedules await client.SetCpuModeAsync(RunMode.Auto, 0); Console.WriteLine(“Computations resumed to automatic mode.”); Use code with caution. The RunMode enumeration generally includes: Always: Computes continuously regardless of user activity.
Auto: Computes based on user-configured preferences (e.g., only when idle). Never: Suspends all processing. Conclusion
With BoincGuiRpc.Net, building custom automation tools, monitoring utilities, or centralized management dashboards for BOINC in C# is straightforward. By leveraging simple asynchronous methods, you can seamlessly integrate distributed computing control into any enterprise or personal .NET application. If you want to tailor this further, tell me:
Leave a Reply