arpit solanki

← all posts

How I wrote a TCP server in C from scratch

How I wrote a TCP server in C from scratch ....

-> first I deep dived into TCP theory and all the terminologies involved, medium blogs came helpful, and a bunch of Youtube videos on TCP and networking (yt is the savior at the end of the day)
-> Got to learn the concepts of networking and how things work under the hood. Realized frameworks abstract a lot of detail and complexity while doing things.
-> After having a grasp of networking jargon and learning about system calls, I faced issues like windows OS had some difference in system calls as compared to Linux and most of the blogs for this are available on Linux based calls, so I continued the project in WSL.
-> I realized that C might be an older language, but it gives so much hardware control and modifications at OS level. Concluded "C ain't ordinary".
-> Took a lot of help from LLMs as i was unaware of most of the syntax used here from libraries and also got to know about lot of libraries of C related to networking like sys/socket.h, netinet/in.h, arpa/inet.h.
-> Why I used C?

  • because C is very fast, no garbage collection so no runtime overhead.
  • C gives direct access to system calls like socket(), bind(), listen(), and accept()
  • there is no layer of abstraction, coding things from scratch feels different 🙂

Github repo - boss6825/TCP-server-in-C

I am thinking of scaling it to a multi-client TCP chat server in C using multi-threading
will post about this project in future......