I'm always excited to take on new projects and collaborate with innovative minds.

Phone

+977 9807718500

Email

harshchy143@gmail.com

Website

harshchaudhary.com.np

Address

Kathmandu, Nepal

Social Links

Web Development

A behind-the-scenes look at how I built a real-time LAN chat room with file sharing, using C++ sockets that run on both Windows and macOS.

A behind-the-scenes look at how I built a real-time LAN chat room with file sharing, using C++ sockets that run on both Windows and macOS.

This project started as a course assignment for Network Programming but quickly evolved into a full-fledged LAN messaging and file-sharing system — complete with timestamps, file transfer, message logging, and cross-platform support.

My goal was to build a real-time terminal-based chat system that supports multiple users over LAN, allows file sharing, and works seamlessly on both Windows and macOS. The final result is a clean, command-line powered tool that I'm proud to open source.


Project Goals

  • Enable real-time multi-user LAN chat
  • Allow sending and receiving files between clients
  • Implement a command-driven terminal interface
  • Log all messages to a file
  • Auto-organize received files
  • Ensure compatibility on Windows and macOS

Tech Stack

  • Language: C++
  • Networking: Winsock2 (Windows) and BSD sockets (macOS)
  • Threads: std::thread
  • Build tools: g++, MinGW, clang++
  • Editors: VS Code / Code::Blocks
  • Terminal UI: Console output, ANSI color formatting (macOS)

Architecture

The application follows a client-server model. The server handles multiple clients using threads. Messages and files sent from any client are received by the server and broadcast to all other clients.

+-----------+       +-------------+       +-----------+
|  Client A | <---> |   Server    | <---> |  Client B |
+-----------+       +-------------+       +-----------+
       \                                   /
        \--------- File Relay ------------/

Files are broken into chunks and reassembled on the receiving client’s side. A simple protocol using FILE:<filename> and FILE_END markers was used for file transfer.


Key Features

  • Real-time messaging over TCP
  • File transfer capability
  • Timestamped messages
  • Chat logs saved to chatlog.txt
  • Received files stored in the received/ folder
  • Terminal commands: /help, /file, /list, /exit
  • Cross-platform: works on Windows and macOS

Challenges Faced

  • Handling socket differences between Winsock and BSD sockets
  • Ensuring inet_pton() compatibility on Windows (fallback to inet_addr())
  • Thread-safe broadcasting and file handling
  • Folder creation logic across platforms (_mkdir on Windows, mkdir on macOS)
  • Chunked file transfer and recognizing file boundaries with FILE_END

Enhancements I Added

  • Server now displays when a user connects or disconnects,
  • Received files are auto-organized into a folder,
  • All messages (including system messages) are timestamped and logged,
  • The /help command shows all supported actions.

Screenshots

user2-1.png
Client A
user1-1.png
Client B
user3-1.png
Client3
server.png
Server Logs

What I Learned

This project taught me practical low-level networking — from socket creation to file transfer protocols. I learned how to write threaded applications in C++ and how to make code portable across operating systems. Debugging platform-specific issues also helped me better understand system-level development.


What’s Next

  • Add encryption (SSL or AES) for secure communication
  • Build a GUI version using Qt or Win32 API
  • Implement LAN discovery using UDP broadcast
  • Add file transfer progress indicators
  • Export chat logs to HTML or Markdown

Source Code

You can find the full project source code on GitHub:
https://github.com/harsh4dev/LanChatroomNP


Thanks for reading! I hope this helps anyone curious about building networked C++ applications. Feel free to test it out or fork it — and message me (over LAN or GitHub 😄)!

C++ chat app, C++ file transfer, LAN chat project, socket programming, Winsock, BSD sockets, cross-platform C++, real-time chat, TCP socket chat, C++ project idea, network programming, multi-client chat, file sharing, C++ networking tutorial
3 min read
Jul 16, 2025
By Harsh Chaudhary
Share

Leave a comment

Your email address will not be published. Required fields are marked *

Related posts

Jun 22, 2025 • 3 min read
Pokhara University B.E. Software Engineering (BESE) – Complete New Course Structure & Syllabus [2022]

Explore the complete semester-wise course structure of the BE Software...

Jun 03, 2025 • 3 min read
How to Build a Developer Portfolio That Stands Out in 2025
Jun 03, 2025 • 3 min read
Top Frontend Frameworks in 2025: Which One Should You Learn?