Skip to content

Latest commit

 

History

History
55 lines (37 loc) · 1.85 KB

File metadata and controls

55 lines (37 loc) · 1.85 KB

Languages: English | 简体中文 | 繁體中文 | 日本語 | 한국어 | Français | Deutsch | Español | Italiano | Русский | العربية

← NeverC Examples

Linux Network Socket Example

A TCP client/server demo cross-compiled to Linux using NeverC. Both client and server run in the same process using loopback for simplicity.

NeverC bundles a Linux sysroot (Ubuntu 22.04, glibc 2.35) in runtime/linux/, so a single invocation handles preprocessing, compilation, optimization (auto-LTO), and linking via the built-in linker.

Build

From the repo (default target: x86_64-linux-gnu):

cd examples/linux-network
neverc make          # debug: -g (default on the first build)
neverc make release  # release: -O2 --strip
neverc make debug    # switch back to debug

The Makefile persists PROFILE, so later neverc make keeps the same debug/release selection. Release uses NeverC's integrated --strip: debug metadata and unneeded static symbol names are removed while loader/dynamic ABI names that the binary still needs are preserved. See Release builds.

Build for AArch64:

neverc make TARGET=aarch64-linux-gnu

Manual build (without Make)

neverc --target=x86_64-linux-gnu -Wall -o network-demo main.c

Run

Copy network-demo to a Linux machine (or Docker container) and execute:

chmod +x network-demo
./network-demo

What it does

  • Creates a TCP server on a random port (127.0.0.1)
  • Connects a client to the server
  • Sends 3 messages from client to server and prints the received data
  • Demonstrates socket, bind, listen, accept, connect, send, recv