Skip to content

Lesson 02 concurrent server#2

Open
zeshhaan wants to merge 2 commits into
mainfrom
lesson-02-concurrent-server
Open

Lesson 02 concurrent server#2
zeshhaan wants to merge 2 commits into
mainfrom
lesson-02-concurrent-server

Conversation

@zeshhaan

Copy link
Copy Markdown
Owner

No description provided.

claude and others added 2 commits October 21, 2025 07:57
- Add TCP server that listens on port 4000 and handles single HTTP request
- Implement core TCP lifecycle: listen, accept, receive, send, close
- Add detailed comments explaining :gen_tcp options and flow
- Update Elixir version requirement to 1.14 for compatibility

This is the first step in learning Elixir by building an HTTP server from scratch.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Lesson 02: Concurrent TCP Server

New Features:
- Add accept_loop with tail recursion for infinite accept loop
- Spawn isolated process for each client connection
- Enable concurrent handling of multiple requests
- Add comprehensive LEARNING.md documentation

Key Concepts Demonstrated:
- Elixir process spawning with spawn/1
- Tail call optimization (TCO) for infinite recursion
- Process isolation (crashes don't affect other clients)
- Concurrency pattern: accept → spawn → recurse immediately

Technical Details:
- Each client handled in separate process (~2KB memory)
- accept_loop never waits for spawned processes
- Processes exit naturally when request completes
- Can handle thousands of concurrent connections

Documentation:
- Complete explanation of TCP, sockets, and HTTP
- Detailed breakdown of recursion vs tail recursion
- Step-by-step code walkthrough with timeline diagrams
- Testing guide including Observer visualization
- Comparison of Elixir processes vs OS threads

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants