Files
OmniSocketGo/c/README.md
2026-03-30 13:52:56 +08:00

2.3 KiB

OmniSocketC

Linux-only C11 implementation of the UDP/KCP transport stack from OmniSocketGo.

This subtree is intentionally standalone. The Go code stays in place as the behavior reference, while the C implementation builds its own binaries under c/bin/.

Build

cd c
make

Build outputs:

  • c/bin/udpserver
  • c/bin/udppeer
  • c/bin/udpping
  • c/bin/udprelay
  • c/bin/kcpserver
  • c/bin/kcppeer
  • c/bin/kcpping

Run On Different Machines

Server D runs the KCP hub on 0.0.0.0:10909:

./c/bin/kcpserver -listen 0.0.0.0:10909 \
  -kcp-ts-debug-log logs/d-kcp-ts.jsonl \
  -kcp-session-stats-log logs/d-kcp-stats.jsonl

Relay C runs a raw UDP forwarder to D:

./c/bin/kcpserver -mode=relay -listen 0.0.0.0:10909 -relay-remote 172.21.32.15:10909

Peer A dials D through relay C:

./c/bin/kcppeer -id peer-a -server 172.21.32.15:10909 -relay-via 106.55.173.235:10909 \
  -inbox-dir inbox/a \
  -latency-log logs/a-latency.jsonl \
  -kcp-ts-debug-log logs/a-kcp-ts.jsonl \
  -kcp-session-stats-log logs/a-kcp-stats.jsonl

Peer B dials D directly:

./c/bin/kcppeer -id peer-b -server 81.70.156.140:10909 \
  -inbox-dir inbox/b \
  -latency-log logs/b-latency.jsonl \
  -kcp-ts-debug-log logs/b-kcp-ts.jsonl \
  -kcp-session-stats-log logs/b-kcp-stats.jsonl

Optional ping / echo tools:

./c/bin/kcpping -id peer-a -server 106.55.173.235:10909 -echo
./c/bin/kcpping -id peer-b -server 81.70.156.140:10909 -to peer-a -count 20 -interval 100ms
./c/bin/udpserver -listen 0.0.0.0:9001
./c/bin/udppeer -id peer-a -server 127.0.0.1:9001
./c/bin/udpping -id pinger -server 127.0.0.1:9001 -to peer-a -count 20

Interactive Commands

udppeer and kcppeer support the same interactive shell:

help
text peer-b hello
text peer-a hi
file peer-a /tmp/test125.bin
quit

Notes

  • The C project targets Linux only.
  • It preserves the Go wire format for UDP datagrams and KCP stream frames.
  • It keeps runtime JSONL logging, UDP TX timestamp debug, KCP packet debug, and KCP session stats.
  • Offline latencysummary and HTML chart generation are intentionally not migrated.
  • No automated C tests are included in this subtree; validation is expected to happen on Linux via make and manual smoke tests.