net.tcl is a minimalist Tcl module for managing TCP client connections using non-blocking sockets. Built around Tcl's socket and fileevent, it provides a streamlined API for connecting, sending, and receiving data over TCP, ideal for modular systems or interprocess communication in VPN-secured environments.
- Simple TCP client interface using Tcl's native socket API
- Returns a dedicated namespace as handler for each connection
- Non-blocking I/O using
fileeventinternally - Designed for modular systems (like Rivet-connected or daemon-based flows)
- No external dependencies
- Cleanly handles open/send/receive/close logic
- Suitable for intra-VPN communication
# Connect to a server, receive a handler namespace
set conn [net::client::connect 127.0.0.1 9000]
# Send data through the connection
$conn send "Hello from Tcl!"
# Close the connection
$conn closenet::client::connect: Opens a socket and returns a handler namespace$handler send: Sends string data over the socket$handler close: Closes the connection cleanly
Handlers can be renamed for clarity:
set conn [net::client::connect 127.0.0.1 9000]
rename $conn ::handler
::handler send "Using a renamed handler"MIT (or your preferred open-source license)
Created to support lightweight interprocess communication in modular Tcl projects.
If this project has been helpful to you or saved you some development time, consider buying me a coffee! Your support helps me keep exploring new optimizations and sharing quality code.