CSend is a cross-platform peer-to-peer chat application written in C, supporting both modern POSIX systems and Classic Macintosh (System 7.x). It demonstrates network programming across different eras of computing, from modern multi-threaded applications to single-threaded GUI applications.
- Dual Network Stack Support: Full implementations for both MacTCP and OpenTransport on Classic Mac
- Automated Testing: Built-in test feature for reliable cross-platform validation
- Shared UI Components: Modular dialog components shared between MacTCP and OpenTransport builds
- Enhanced Logging: Platform-specific log files with categorized output filtering
- Memory Optimization Experiments: Mac SE build target (work in progress)
- Latest Demo - Current functionality showcase
- Original Demo - Early version (functionality has evolved significantly)
- Multi-threaded Architecture: Separate threads for input, networking, and discovery
- Terminal Interface: Command-line chat with intuitive commands
- Machine Mode: JSON-based API for programmatic interaction
- Claude AI Integration: Built-in chatbot using Anthropic's Claude Haiku
- Docker Support: Easy multi-peer testing with containerized instances
- Real-time Discovery: Automatic peer detection on local networks
- Native GUI: True Classic Mac interface using Dialog Manager
- Dual Network Stacks: Full MacTCP and OpenTransport implementations
- Multiple Build Targets: 68K (MacTCP & OpenTransport), Mac SE optimized
- Retro68 Compatible: Builds with modern cross-compiler
- Event-driven Architecture: Single-threaded with asynchronous operations
- Automated Testing: Built-in "Perform Test" feature accessible from File menu
- Unified Protocol: Custom message format for cross-platform compatibility
- UDP Discovery: Broadcast-based peer discovery
- TCP Messaging: Reliable direct communication between peers
- Peer Management: Automatic timeout handling and status tracking
The project uses a shared core design with platform-specific implementations:
csend/
โโโ shared/ # Platform-independent core logic
โ โโโ protocol.c # Message format and parsing
โ โโโ peer.c # Peer list management
โ โโโ discovery.c # UDP peer discovery logic
โ โโโ messaging.c # TCP message handling
โ โโโ logging.c # Centralized logging system
โ โโโ test.c # Cross-platform automated test core
โ โโโ classic_mac/ # Shared Classic Mac UI components
โ โโโ ui/ # Dialog input, messages, and peer list
โโโ posix/ # POSIX implementation
โ โโโ main.c # Multi-threaded event loop
โ โโโ ui_terminal.c # Terminal interface
โ โโโ ui_terminal_machine.c # JSON machine mode interface
โ โโโ commands.c # Command processing
โ โโโ network.c # POSIX networking
โ โโโ test.c # POSIX test adapter
โโโ classic_mac_mactcp/ # Classic Mac MacTCP (68K)
โ โโโ main.c # Event-driven GUI loop
โ โโโ dialog.c # Dialog Manager interface
โ โโโ mactcp_impl.c # MacTCP networking implementation
โ โโโ tcp_state_handlers.c # TCP connection state machine
โ โโโ test.c # MacTCP test adapter
โโโ classic_mac_ot/ # Classic Mac OpenTransport (68K)
โโโ main.c # Event-driven GUI loop
โโโ dialog.c # Dialog Manager interface
โโโ opentransport_impl.c # OpenTransport networking
โโโ test.c # OpenTransport test adapter
Messages use the format: MSG_MAGIC_NUMBER|TYPE|SENDER@IP|CONTENT
Message Types:
MSG_DISCOVERY
- Peer discovery broadcastsMSG_DISCOVERY_RESPONSE
- Discovery repliesMSG_TEXT
- Chat messagesMSG_QUIT
- Graceful disconnect notifications
git clone https://github.com/matthewdeaves/csend.git
cd csend
make
./build/posix/csend_posix alice
# Start multiple peer containers
scripts/docker.sh start
# Check container status
scripts/docker.sh status
# Stop all containers
scripts/docker.sh stop
# Set up Anthropic API key
export ANTHROPIC_API_KEY="your-api-key-here"
# Run Claude chatbot
scripts/run_machine_mode.sh --chatbot
- Retro68 cross-compiler (setup guide)
- Classic Mac OS environment (QemuMac recommended)
# Quick setup for Retro68
scripts/setup_retro68.sh
# Build Classic Mac MacTCP version (68K, System 7)
make -f Makefile.retro68.mactcp
# Build Classic Mac OpenTransport version (68K, System 7.5+)
make -f Makefile.retro68.ot
# Build Mac SE optimized version (68K, WIP - currently requires >4MB RAM)
make -f Makefile.retro68.mactcp.se # Note: Not yet working on 4MB Mac SE
Output files (example for MacTCP):
build/classic_mac_mactcp/csend-mac.APPL
- Application bundlebuild/classic_mac_mactcp/csend-mac.bin
- MacBinary format (most portable)build/classic_mac_mactcp/csend-mac.dsk
- Floppy disk image
- Transfer
csend-mac.bin
to your Classic Mac environment - Use binUnpk or Stuffit Expander to decode the MacBinary file
- Double-click the extracted application to run
/list # Show active peers
/send <peer_num> <message> # Send private message
/broadcast <message> # Send to all peers
/debug # Toggle debug output
/quit # Exit gracefully
/help # Show command help
- Message Input: Type in the bottom text field
- Send Button: Send message to selected peer or broadcast
- Peer List: Click to select message recipient
- Broadcast Checkbox: Send to all peers when checked
- Debug Checkbox: Show debug messages
- File Menu โ Perform Test: Run automated test sequence (broadcasts + direct messages)
- Close Box: Quit application (sends quit notifications)
# Start machine mode
./build/posix/csend_posix --machine-mode claude
# JSON command examples
/list --id=1
/send 1 "Hello!" --id=2
/status --id=3
See Machine Mode Documentation for full API reference.
This project uses Doxygen to generate comprehensive documentation from the source code comments.
- Doxygen: Ensure you have Doxygen installed. You can download it from doxygen.org.
- Graphviz (optional, for diagrams): For generating diagrams and graphs in the documentation, you'll need to install Graphviz. You can get it from graphviz.org.
To generate the documentation, run the following command from the root of the project:
doxygen Doxyfile
The documentation will be generated in the doxygen_docs/html
directory. Open index.html
in that directory to view the documentation.
Format code (required before commits):
scripts/format_code.sh
Check for duplicated code:
scripts/cpd_check.sh
Analyze complexity:
scripts/complexity_check.sh warnings # Show only complex functions
scripts/complexity_check.sh detailed # Generate HTML reports
Detect dead code:
scripts/deadcode_check.sh warnings # Show compiler warnings
scripts/deadcode_check.sh # Full analysis
Filter logs:
scripts/filter_logs.sh csend_posix.log NETWORK DISCOVERY
# POSIX build
make clean && make
# Classic Mac MacTCP build (requires Retro68)
make -f Makefile.retro68.mactcp
# Classic Mac OpenTransport build (requires Retro68)
make -f Makefile.retro68.ot
# Docker multi-peer test
scripts/docker.sh start
- Automated Testing: Built-in
/test
command (POSIX) or "Perform Test" menu item (Classic Mac) - Unit Testing: No formal framework (contributions welcome)
- Integration Testing: Use Docker setup for multi-peer scenarios
- Machine Mode Testing:
tools/test_machine_mode.py
for automated JSON API testing - Logging: Enable debug mode and check platform-specific log files:
- POSIX:
csend_posix.log
- MacTCP:
csend_mac.log
- OpenTransport:
csend_classic_mac_ot_ppc.log
- POSIX:
- K&R style with 4-space indentation
- Complexity limits: CCN โค 10, function length โค 60 lines
- Thread safety: POSIX peer list protected by mutex
- Error handling: Comprehensive logging with categories
File | Description |
---|---|
CLAUDE.md | Development guidelines for AI assistants |
MACHINE_MODE.md | Complete machine mode API reference |
LOGGING.md | Logging system documentation |
TAGS.md | Development milestone history |
resedit.md | ResEdit and resource conversion guide |
csend/
โโโ posix/ # POSIX-specific source code
โโโ classic_mac_mactcp/ # Classic Mac MacTCP implementation (68K)
โโโ classic_mac_ot/ # Classic Mac OpenTransport implementation (68K)
โโโ shared/ # Platform-independent core logic
โ โโโ classic_mac/ # Shared Classic Mac UI components
โโโ MPW_resources/ # Classic Mac GUI resources
โโโ tools/ # Python tools and client libraries
โโโ scripts/ # Shell scripts for building and testing
โโโ docs/ # Documentation and images
โโโ resources/ # External resources (Books, MPW interfaces)
โโโ logs/ # Log files (generated)
โโโ reports/ # Analysis reports (generated)
โโโ build/ # Compiled binaries (generated)
โโโ doxygen_docs/ # Generated documentation (if built)
โโโ .finf/ # SheepShaver metadata (preserves Mac resource forks)
โโโ Makefile # POSIX build configuration
โโโ Makefile.retro68.mactcp # Classic Mac MacTCP build (68K)
โโโ Makefile.retro68.ot # Classic Mac OpenTransport build (68K)
โโโ Makefile.retro68.mactcp.se # Mac SE build (WIP)
โโโ Dockerfile # Docker container setup
โโโ docker-compose.yml # Multi-container orchestration
โโโ chatbot_config.json # Claude chatbot configuration
โโโ README.md # This file
โโโ CLAUDE.md # AI assistant development guidelines
- JSON API: Structured programmatic interface
- Claude Chatbot: AI-powered chat participant
- Correlation IDs: Request/response tracking
- Event Streaming: Real-time peer and message events
- Python Client: Async client library for automation
- UDP Discovery: Broadcast-based peer discovery on port 2556
- TCP Messaging: Direct peer communication on port 2555
- Dual Streams (Mac): Separate listen/send TCP connections
- Message Queuing: Buffered broadcasts during busy periods
- Timeout Handling: Automatic peer pruning (30-second timeout)
- Endian Handling: Network byte order for message magic numbers
- Time Abstraction:
time()
(POSIX) vsTickCount()
(Mac) - Threading Models: Multi-threaded (POSIX) vs event-driven (Mac)
- UI Abstraction: Terminal vs GUI with consistent command processing
- Format your code: Run
scripts/format_code.sh
before committing - Check complexity: Keep functions under complexity thresholds
- Test thoroughly: Use Docker setup for multi-peer testing
- Document changes: Update relevant documentation files
- Follow patterns: Study existing platform implementations
- C compiler (GCC recommended)
- Make build tool
- Pthreads support
- Standard POSIX socket libraries
- Retro68 cross-compiler
- Classic Mac OS environment for testing (SheepShaver recommended)
- ResEdit for GUI resource editing (optional)
- Note:
.finf
folders preserve Mac resource/data forks when transferring files from emulator
- Docker Engine
- Docker Compose
- Compatible terminal emulator
- Python 3.6+
- Anthropic API key
- Virtual environment (automatically managed by launcher)
This project demonstrates cross-platform network programming techniques and is available for educational and research purposes.
A bridge between computing eras - from Classic Mac to modern POSIX systems