gRPC API
NetClamp’s gRPC surface lives at 127.0.0.1:9846 and mirrors what the
REST API does, with one bonus: low-latency
streaming for live events. If your client is gRPC-native, use this; if
you’re scripting with curl or PowerShell Invoke-RestMethod, REST is
simpler.
Authentication
Same bearer token as REST (C:\ProgramData\NetClamp\auth.token).
Pass it as gRPC metadata:
authorization: Bearer <token>
Service definition
The single service is netclamp.NetClampService. Highlights:
|
Service health snapshot (same fields as |
|
Per-app traffic data. |
|
Live socket table. |
|
Rule CRUD. |
|
Quota CRUD. |
|
Server-streaming RPC: quota busts, rule sync alerts, BFE recovery events. Connect once, leave open. |
Getting the .proto
The schema is published with every release at:
C:\Program Files\NetClamp\proto\netclamp.proto
Or copy it out of the installer’s proto/ directory before installing.
Quick start — Python
pip install grpcio grpcio-tools
python -m grpc_tools.protoc -I"C:\Program Files\NetClamp\proto" `
--python_out=. --grpc_python_out=. netclamp.proto
import grpc
import netclamp_pb2, netclamp_pb2_grpc
with open(r"C:\ProgramData\NetClamp\auth.token") as f:
token = f.read().strip()
channel = grpc.insecure_channel("127.0.0.1:9846")
stub = netclamp_pb2_grpc.NetClampServiceStub(channel)
md = [("authorization", f"Bearer {token}")]
status = stub.GetStatus(netclamp_pb2.GetStatusRequest(), metadata=md)
print(f"WFP active: {status.wfp_active}, rules: {status.active_rules}")
for evt in stub.StreamEvents(netclamp_pb2.StreamEventsRequest(), metadata=md):
print(evt.kind, evt.detail)
Quick start — Go
protoc --go_out=. --go-grpc_out=. -I"C:\Program Files\NetClamp\proto" netclamp.proto
conn, _ := grpc.Dial("127.0.0.1:9846", grpc.WithInsecure())
md := metadata.New(map[string]string{"authorization": "Bearer " + readToken()})
ctx := metadata.NewOutgoingContext(context.Background(), md)
client := pb.NewNetClampServiceClient(conn)
status, _ := client.GetStatus(ctx, &pb.GetStatusRequest{})
When to choose gRPC over REST
-
You need event streams (quota busts, rule sync state changes) and don’t want to manage Server-Sent Events reconnection logic.
-
You’re writing a daemon that talks to NetClamp continuously and care about per-RPC overhead.
-
Your language has good gRPC tooling already wired (Go, Rust, C#, Java).
For one-shot scripts, REST is usually less ceremony.
Status codes
Standard gRPC status codes apply:
|
Success. |
|
Missing or wrong bearer token. |
|
Request body failed validation. |
|
Resource doesn’t exist. |
|
E.g. |
|
Unexpected. The server log has the detail. |
|
Transient — retry with backoff. |