Skip to content
Personal

MultiChat

2021-06-07 — 2021-06-17

Multi-user real-time chat application built with TCP/IP socket programming and multi-threading — custom text protocol design, per-client thread management, and tkinter event loop integrated with socket threads

MultiChat project cover image

Project Description

A real-time chat system with server-client architecture built using Python's socket module and multi-threading. The server accepts client connections via TCP sockets (AF_INET, SOCK_STREAM) and spawns a dedicated thread per connection using _thread.start_new_thread for concurrent multi-user handling. Designed a custom text protocol with pipe (|) delimiter to distinguish login handshake (id,|nickname), chat messages (nickname|content), and system commands ([접속인원], [kick], [아이디 중복]), broadcasting messages to all clients by iterating a global socket list. The client separates send/receive into independent threading.Thread instances, coordinating with the tkinter GUI event loop through flag-based inter-thread communication (flag_send, flag_out) to handle socket I/O and UI updates simultaneously.

Highlights

  • TCP socket multi-threaded server with per-client dedicated threads
  • Custom text protocol with pipe delimiter for message type separation
  • Integrated tkinter GUI event loop with socket I/O threads
  • Server-side nickname validation and admin kick protocol

Features

  • TCP socket server — socket.bind/listen/accept based server start/stop, dedicated thread per client connection (start_new_thread)
  • Custom text protocol — pipe (|) delimiter for message type separation, bracket prefix commands ([접속인원], [kick], [아이디 중복], [시스템 추방]) for system command framework
  • Nickname duplicate validation — server-side nickname list comparison, connection rejection via NameError exception with client notification on duplicates
  • Real-time connected user list sync — broadcasting [접속인원] message to all clients on connect/disconnect/kick events for list refresh
  • Server admin kick feature — nickname-based client identification, [kick] command transmission, socket list removal and system-wide announcement
  • tkinter GUI — independent GUI for server and client, Text widget-based chat log and user list, Entry widget-based input

Lessons Learned

  • 💡 Internalized core network programming principles (binding, listening, accepting, data transmission) by directly implementing TCP socket accept-recv-send flow, understanding the necessity of byte encoding/decoding
  • 💡 Built a concurrent server model with per-client dedicated threads, recognizing concurrency issues and thread safety importance when using global lists as shared resources
  • 💡 Learned message framing and type differentiation by designing a delimiter-based text protocol from scratch — establishing foundation for understanding higher-level protocol design (WebSocket, HTTP)
  • 💡 Resolved conflicts between tkinter's main loop (mainloop) and socket blocking I/O through thread separation and flag-based inter-thread communication, learning async processing patterns in GUI applications

Tech Stack

Python socket threading tkinter

Project Images