# Grpc.Core.RpcException: Status(StatusCode="Unavailable", Detail="无法连接到所有地址；最后一个错误：UNKNOWN: ipv4:192.168.1.1:443: 无法建立连接，因为目标计算机主动拒绝了连接。")

- **ID:** `dotnet/grpc-unavailable-connectivity`
- **领域:** dotnet
- **类别:** network_error
- **错误码:** `Unavailable`
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

gRPC 客户端无法到达服务器，因为服务器未运行、端口被防火墙阻止或端点地址不正确。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| net6.0 | active | — | — |
| net7.0 | active | — | — |
| net8.0 | active | — | — |
| net9.0 | active | — | — |

## 解决方案

1. ```
   Verify the server is running and listening on the expected port. Use 'netstat -an | findstr :443' (Windows) or 'ss -tuln | grep 443' (Linux) to check. Restart the gRPC server service if needed.
   ```
2. ```
   Check firewall rules. For Windows, run 'netsh advfirewall firewall add rule name="gRPC" dir=in action=allow protocol=TCP localport=443'. For Linux, use 'ufw allow 443/tcp' or adjust iptables.
   ```
3. ```
   Ensure the client endpoint URL matches the server's listening address. For example, if the server uses 'https://localhost:5001', the client should set 'new GrpcChannel.ForAddress("https://localhost:5001")'. Use DNS resolution with 'nslookup server.example.com' to verify IP.
   ```

## 无效尝试

- **Increasing the deadline or timeout in the gRPC call** — The server is not responding at all; a longer timeout only delays the failure but does not establish a connection. (95% 失败率)
- **Disabling SSL/TLS on the client side** — If the server requires HTTPS, disabling TLS will cause a different error (e.g., protocol mismatch), not fix the connection refusal. (80% 失败率)
- **Changing the port number arbitrarily** — Unless the correct port is used, the connection will still be refused; this is a guess rather than a fix. (90% 失败率)
