Skip to content

Commit 887a7fe

Browse files
fix: RGB connection — force IPv4 (127.0.0.1) instead of localhost
ROOT CAUSE: OpenRGB server binds 0.0.0.0 (IPv4 only) but FANZi connected via 'localhost' which resolves to ::1 (IPv6) on Windows — connection fails. Confirmed with standalone test: OpenRGB.NET connects fine to 127.0.0.1:6742, finds ASUS PRIME Z590-P with 2 LEDs, 3 zones, sets them to blue successfully.
1 parent 3d24044 commit 887a7fe

5 files changed

Lines changed: 144 additions & 2 deletions

File tree

src/Fanzi.FanControl/Services/OpenRgbService.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,13 @@ public Task<bool> TryConnectAsync(
5151
ServerVersion = "Not connected";
5252
ModeSwitchStatus = "";
5353

54+
// Force IPv4 — OpenRGB server only binds 0.0.0.0, and
55+
// "localhost" resolves to ::1 (IPv6) on Windows which fails.
56+
string connectHost = host.Equals("localhost", StringComparison.OrdinalIgnoreCase)
57+
? "127.0.0.1" : host;
58+
5459
var client = new OpenRgbClient(
55-
ip: host,
60+
ip: connectHost,
5661
port: port,
5762
name: "FANZI",
5863
autoConnect: false,

src/Fanzi.FanControl/ViewModels/RgbControlViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public sealed partial class RgbControlViewModel : ViewModelBase, IDisposable
7474
public string ConnectButtonText => IsConnecting ? "Connecting…" : "Connect";
7575

7676
[ObservableProperty]
77-
private string _openRgbHost = "localhost";
77+
private string _openRgbHost = "127.0.0.1";
7878

7979
[ObservableProperty]
8080
private int _openRgbPort = 6742;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
<TargetFramework>net10.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
</PropertyGroup>
7+
<ItemGroup>
8+
<PackageReference Include="OpenRGB.NET" Version="3.1.1" />
9+
</ItemGroup>
10+
</Project>

src/Fanzi.OpenRgbTest/Program.cs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
using OpenRGB.NET;
2+
using System;
3+
4+
try
5+
{
6+
Console.WriteLine("=== OpenRGB Connection Test ===");
7+
Console.WriteLine($"Connecting to localhost:6742...");
8+
9+
var client = new OpenRgbClient(
10+
ip: "127.0.0.1",
11+
port: 6742,
12+
name: "FANZI-TEST",
13+
autoConnect: false,
14+
protocolVersionNumber: 4);
15+
16+
client.Connect();
17+
Console.WriteLine("Connect() succeeded!");
18+
19+
Console.WriteLine("Connect() OK — fetching devices...");
20+
21+
var devices = client.GetAllControllerData();
22+
Console.WriteLine($"Found {devices.Length} device(s):");
23+
24+
for (int i = 0; i < devices.Length; i++)
25+
{
26+
var d = devices[i];
27+
Console.WriteLine($" [{i}] {d.Name} ({d.Type}) — {d.Leds.Length} LEDs, {d.Zones.Length} zones");
28+
Console.WriteLine($" Active mode: {d.ActiveMode?.Name ?? "?"} (index {d.ActiveModeIndex})");
29+
30+
// Try setting Direct mode
31+
try
32+
{
33+
for (int m = 0; m < d.Modes.Length; m++)
34+
{
35+
string modeName = d.Modes[m].Name ?? "";
36+
Console.WriteLine($" Mode [{m}]: {modeName}");
37+
}
38+
39+
client.SetCustomMode(i);
40+
Console.WriteLine($" SetCustomMode() OK");
41+
}
42+
catch (Exception ex)
43+
{
44+
Console.WriteLine($" SetCustomMode() failed: {ex.Message}");
45+
}
46+
47+
// Try sending a colour
48+
try
49+
{
50+
var colors = new OpenRGB.NET.Color[d.Leds.Length];
51+
for (int k = 0; k < colors.Length; k++)
52+
colors[k] = new OpenRGB.NET.Color(0, 100, 255); // Blue
53+
client.UpdateLeds(i, colors);
54+
Console.WriteLine($" UpdateLeds() OK — set all LEDs to blue");
55+
}
56+
catch (Exception ex)
57+
{
58+
Console.WriteLine($" UpdateLeds() failed: {ex.Message}");
59+
}
60+
}
61+
62+
client.Dispose();
63+
Console.WriteLine("=== Test complete ===");
64+
}
65+
catch (Exception ex)
66+
{
67+
Console.WriteLine($"FATAL: {ex.GetType().Name}: {ex.Message}");
68+
Console.WriteLine(ex.StackTrace);
69+
}

test-openrgb.csx

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/env dotnet-script
2+
// Quick OpenRGB protocol test
3+
using System;
4+
using System.Net.Sockets;
5+
using System.Text;
6+
using System.Threading;
7+
8+
var tcp = new TcpClient();
9+
tcp.Connect("127.0.0.1", 6742);
10+
Console.WriteLine("TCP connected OK");
11+
12+
var stream = tcp.GetStream();
13+
stream.ReadTimeout = 3000;
14+
15+
// Send OpenRGB protocol handshake: "OPEN" + uint32 protocol version
16+
var magic = Encoding.ASCII.GetBytes("OPEN");
17+
var version = BitConverter.GetBytes((uint)4);
18+
var handshake = new byte[magic.Length + version.Length];
19+
Buffer.BlockCopy(magic, 0, handshake, 0, magic.Length);
20+
Buffer.BlockCopy(version, 0, handshake, magic.Length, version.Length);
21+
stream.Write(handshake, 0, handshake.Length);
22+
Console.WriteLine($"Sent handshake: OPEN v4 ({handshake.Length} bytes)");
23+
24+
Thread.Sleep(1000);
25+
26+
// Read response
27+
var buf = new byte[256];
28+
try
29+
{
30+
int read = stream.Read(buf, 0, 256);
31+
Console.WriteLine($"Received {read} bytes");
32+
33+
// Check for "ORGB" magic in response
34+
if (read >= 4)
35+
{
36+
string responseMagic = Encoding.ASCII.GetString(buf, 0, 4);
37+
Console.WriteLine($"Response magic: '{responseMagic}'");
38+
39+
if (read >= 8)
40+
{
41+
uint serverVersion = BitConverter.ToUInt32(buf, 4);
42+
Console.WriteLine($"Server protocol version: {serverVersion}");
43+
}
44+
}
45+
46+
// Print hex dump
47+
Console.Write("Hex: ");
48+
for (int i = 0; i < Math.Min(read, 32); i++)
49+
Console.Write($"{buf[i]:X2} ");
50+
Console.WriteLine();
51+
}
52+
catch (Exception ex)
53+
{
54+
Console.WriteLine($"Read failed: {ex.Message}");
55+
}
56+
57+
tcp.Close();
58+
Console.WriteLine("Done");

0 commit comments

Comments
 (0)