Skip to content

mjmaher987/My-Twitter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 

Repository files navigation

🐦 My-Twitter

A console-based Twitter (social-network) clone written in C, with a custom client–server architecture over TCP sockets.

Author: Mohammad Javad Maheronnaghsh Course: Basics of Programming — Sharif University of Technology


📋 Overview

My-Twitter re-implements the core of a micro-blogging platform as two native C programs that talk to each other over a TCP connection (Winsock, port 12345):

  • Client — a text-based UI that lets a user sign up, log in, browse a timeline, tweet, follow people, like and comment.
  • Server — accepts client connections, authenticates users with session tokens, processes each request, and persists everything to disk under Resources/ (one folder per user, one file per tweet).

The two halves communicate with a simple plain-text request/response protocol: the client sends a command string (e.g. login, send tweet, follow), the server parses it, updates its file-based store, and replies.

Note: the project targets Windows (it uses winsock2.h, windows.h, conio.h). The client here was written against a ready-made server provided by the course; the server in this repo is the author's own implementation.


🏗️ Architecture

flowchart LR
    subgraph Client [my_client · C]
        UI[Text UI<br/>menus & pages]
        SD[send_data]
        UI --> SD
    end

    subgraph Server [my_server · C]
        ACC[accept loop<br/>port 12345]
        AUTH[token auth]
        H[request handlers]
        ACC --> AUTH --> H
    end

    subgraph Store [Resources/ on disk]
        U[(Users)]
        T[(Tweets)]
    end

    SD -- "TCP request string" --> ACC
    H -- "TCP response" --> SD
    H <--> U
    H <--> T
Loading

🔄 Request Flow (example: posting a tweet)

sequenceDiagram
    participant U as User
    participant C as Client (C)
    participant S as Server (C)
    participant F as Resources/

    U->>C: choose "Tweet"
    C->>S: "login user pass"
    S->>F: verify credentials
    S-->>C: session token
    C->>S: "send tweet <token> <text>"
    S->>F: write tweet file + update timelines
    S-->>C: success
    C-->>U: tweet posted ✅
Loading

✨ Features

Area Supported actions
Accounts Sign up, log in, log out, change password, set bio
Auth Server-issued session tokens per login
Tweets Post tweets, view timeline, refresh, view a profile, delete a tweet
Social Follow / unfollow users, view followers & followings
Engagement Like, comment, show likes/comments
Discovery Search for users/tweets

These map directly to the server's request handlers: signup, login, logout, set bio, send tweet, refresh, profile, follow, unfollow, comment, show, delete.


📂 Repository Structure

My-Twitter/
├── my_client/
│   ├── mainCode/
│   │   ├── main.c          # client UI + networking
│   │   ├── slre.c / slre.h # lightweight regex helper
│   │   └── CMakeLists.txt
│   └── Resources/          # sample Users / Tweets
└── my_server/
    ├── main.c              # server: sockets, auth, handlers, storage
    └── CMakeLists.txt

🚀 Build & Run

The project uses CMake and links against the Windows sockets library (ws2_32).

# 1) Build and start the server
cd my_server
cmake -S . -B build && cmake --build build
./build/my_server        # listens on port 12345

# 2) In a second terminal, build and start the client
cd my_client/mainCode
cmake -S . -B build && cmake --build build
./build/my_client        # connects to 127.0.0.1:12345

If you compile by hand with GCC/MinGW, remember to link Winsock, e.g.:

gcc main.c -o my_server -lws2_32

Then follow the on-screen menu in the client to sign up, log in, and start tweeting.


🛠️ Tech Stack

  • Language: C
  • Networking: Winsock2 (TCP/IP sockets)
  • Build: CMake
  • Storage: flat files under Resources/
  • Extras: SLRE for simple regex matching

About

Basis of Programming Project - Implementing Twitter with C

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors