Skip to content

About

TCP Socket Programming lifecycle implemented across 17 languages with client-server architecture & flowcharts. Built by Nitesh Chaurasiya.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

🌐 MULTI-LANGUAGE TCP SOCKET INFINITE CHAT

⚑ 17 Languages β€’ Client ↔ Server β€’ Infinite Messaging β€’ TCP Networking

Typing SVG

TCP Networking Languages Status


One TCP Client-Server Infinite Chat project implemented across multiple programming languages to understand networking concepts, socket lifecycles, and cross-language communication.


🎯 Choose a Language

Click a language below and open only the section you want to study.








πŸ“Œ Project Overview

This repository contains the same TCP-based Infinite Chat Application implemented in 17 programming languages.

Every implementation follows the same fundamental architecture:

CLIENT πŸ’»
   β”‚
   β”‚ connect()
   β–Ό
SERVER πŸ–₯️
   β”‚
   β”‚ Connection Accepted
   β–Ό
πŸ” MESSAGE EXCHANGE
   β”‚
   β”œβ”€β”€ Client sends message
   β”œβ”€β”€ Server receives message
   β”œβ”€β”€ Server sends reply
   └── Client receives reply
        β”‚
        β–Ό
   Repeat infinitely
        β”‚
        β–Ό
  bye / quit
        β”‚
        β–Ό
 Connection Closed

The exact function names may differ between languages, but the networking lifecycle remains the same.


✨ Features

  • 🌐 TCP/IP based communication
  • πŸ–₯️ Separate Server and Client programs
  • πŸ’¬ Infinite message exchange
  • πŸ” Continuous chat loop
  • πŸ›‘ bye or quit to terminate chat
  • πŸ”’ Proper connection closing
  • 🌍 Can run on two different machines
  • 🧠 Same networking concept across 17 languages
  • πŸ“š Useful for learning socket programming and comparing language APIs

🧠 Socket Programming Mind Map

flowchart TB

    ROOT["🌐 MULTI-LANGUAGE TCP SOCKET CHAT"]

    ROOT --> SERVER["πŸ–₯️ SERVER"]
    ROOT --> CLIENT["πŸ’» CLIENT"]
    ROOT --> CHAT["πŸ’¬ CHAT SYSTEM"]
    ROOT --> LANG["🌍 17 LANGUAGES"]

    SERVER --> S1["⚑ Create Socket"]
    SERVER --> S2["πŸ”— Bind Address"]
    SERVER --> S3["πŸ‘‚ Listen"]
    SERVER --> S4["🀝 Accept"]
    SERVER --> S5["πŸ“€ Send"]
    SERVER --> S6["πŸ“₯ Receive"]
    SERVER --> S7["πŸ”’ Close"]

    CLIENT --> C1["⚑ Create Socket"]
    CLIENT --> C2["🀝 Connect"]
    CLIENT --> C3["πŸ“€ Send"]
    CLIENT --> C4["πŸ“₯ Receive"]
    CLIENT --> C5["πŸ”’ Close"]

    CHAT --> CH1["πŸ” Infinite Loop"]
    CHAT --> CH2["πŸ“‘ TCP Network"]
    CHAT --> CH3["πŸ“ Message Exchange"]
    CHAT --> CH4["πŸ›‘ bye / quit"]

    LANG --> L1["Python / Java / C / C++"]
    LANG --> L2["JavaScript / TypeScript / Shell / PHP"]
    LANG --> L3["Go / Rust / Ruby / Dart"]
    LANG --> L4["Kotlin / Swift / Lua / Perl / C#"]
Loading

πŸ—οΈ System Architecture

flowchart LR

    CLIENT["πŸ’» CLIENT<br/>client file"]

    NETWORK["🌐 TCP/IP NETWORK"]

    SERVER["πŸ–₯️ SERVER<br/>server file"]

    CLIENT -->|"connect()"| SERVER

    CLIENT -->|"send()"| NETWORK
    NETWORK -->|"receive()"| SERVER

    SERVER -->|"send()"| NETWORK
    NETWORK -->|"receive()"| CLIENT
Loading

πŸ”„ Complete TCP Lifecycle

sequenceDiagram
    participant C as πŸ’» Client
    participant S as πŸ–₯️ Server

    S->>S: Create Socket
    S->>S: Bind IP + Port
    S->>S: Listen

    C->>C: Create Socket
    C->>S: Connect

    S->>S: Accept Connection

    loop Infinite Chat
        C->>S: Send Message
        S->>S: Receive Message
        S->>C: Send Reply
        C->>C: Receive Reply
    end

    C->>S: bye / quit
    C->>C: Close Connection
    S->>S: Close Connection
Loading

βš™οΈ Universal Socket Function Mapping

Socket Concept Purpose
socket() / socket creation Creates a communication endpoint
bind() Attaches server to an IP address and port
listen() Waits for incoming connection requests
accept() Accepts a client connection
connect() Client connects to server
send() / write() Sends data
recv() / read() Receives data
close() / shutdown() Closes the connection

Different languages use different APIs. The concept is identical even when the exact function name changes.


πŸ’¬ Infinite Chat Flow

flowchart TD

    START["πŸš€ Start Program"]
    CONNECT["🀝 Establish Connection"]
    SEND["πŸ“€ Send Message"]
    RECEIVE["πŸ“₯ Receive Message"]
    CHECK{"bye / quit?"}
    CLOSE["πŸ”’ Close Connection"]

    START --> CONNECT
    CONNECT --> SEND
    SEND --> RECEIVE
    RECEIVE --> CHECK

    CHECK -->|No| SEND
    CHECK -->|Yes| CLOSE
Loading

πŸ“ Project Structure

socket-programming/
β”‚
β”œβ”€β”€ python-files/
β”œβ”€β”€ java-files/
β”œβ”€β”€ c-files/
β”œβ”€β”€ cpp-files/
β”œβ”€β”€ js-files/
β”œβ”€β”€ typescript-files/
β”œβ”€β”€ shell-files/
β”œβ”€β”€ php-files/
β”œβ”€β”€ go-files/
β”œβ”€β”€ rust-files/
β”œβ”€β”€ ruby-files/
β”œβ”€β”€ dart-files/
β”œβ”€β”€ kotlin-files/
β”œβ”€β”€ swift-files/
β”œβ”€β”€ lua-files/
β”œβ”€β”€ perl-files/
└── csharp-files/

🌐 Running on Two Machines

Before running the project on two different machines:

Step 1 β€” Connect Both Machines

Both devices should normally be connected to the same:

  • Wi-Fi network
  • LAN network
  • Local router

Step 2 β€” Find Server IPv4 Address

On Windows:

ipconfig

Look for:

IPv4 Address

Example:

192.168.1.10

Step 3 β€” Update Client File

Replace the default:

192.168.1.10

with the actual IPv4 address of the machine running the server.

Step 4 β€” Start Server First

Run the server on Machine 1.

Step 5 β€” Start Client

Run the client on Machine 2.

Step 6 β€” Allow Firewall Access

If the connection fails, ensure the firewall allows TCP traffic on:

Port 5000

πŸ“š Language Guides

Dynamic reading tip: Each language is inside a collapsible section. Open only the language you want to study.


🐍 Python

Click to open Python guide

Folder

python-files/
β”œβ”€β”€ server.py
└── client.py

Run Server

python server.py

Run Client

python client.py

Main Python Module

socket

Common Operations

socket()
bind()
listen()
accept()
connect()
send()
recv()
close()

How It Works

  1. Server creates a TCP socket.
  2. Server binds to an IP address and port.
  3. Server listens for clients.
  4. Client creates a socket.
  5. Client connects to the server.
  6. Messages are exchanged continuously.
  7. bye or quit closes the chat.

β˜• Java

Click to open Java guide

Folder

java-files/
β”œβ”€β”€ Server.java
└── Client.java

Compile

javac Server.java
javac Client.java

Run Server

java Server

Run Client

java Client

Main Classes

ServerSocket
Socket
BufferedReader
PrintWriter

Concept Mapping

ServerSocket β†’ bind + listen
accept()     β†’ accept client
Socket       β†’ connect
PrintWriter  β†’ send
BufferedReader β†’ receive
close()      β†’ close

πŸ”΅ C

Click to open C guide

Folder

c-files/
β”œβ”€β”€ server.c
└── client.c

Compile on Linux/macOS

gcc server.c -o server
gcc client.c -o client

Run

./server
./client

Windows

Compile with MinGW or another C compiler.

Socket Functions

socket()
bind()
listen()
accept()
connect()
send()
recv()
close()

C provides one of the closest implementations to the original low-level socket API.


βš™οΈ C++

Click to open C++ guide

Folder

cpp-files/
β”œβ”€β”€ server.cpp
└── client.cpp

Compile

g++ server.cpp -o server
g++ client.cpp -o client

Run

./server
./client

C++ generally uses the same low-level socket concepts as C, combined with C++ input/output features.


🟨 JavaScript (Node.js)

Click to open JavaScript guide

Folder

js-files/
β”œβ”€β”€ server.js
└── client.js

Run Server

node server.js

Run Client

node client.js

Main Module

net

Main Operations

net.createServer()
server.listen()
socket.connect()
socket.write()
data event
socket.end()

πŸ”· TypeScript

Click to open TypeScript guide

Folder

typescript-files/
β”œβ”€β”€ server.ts
└── client.ts

Install TypeScript

npm install -g typescript

Compile

tsc server.ts
tsc client.ts

Run

node server.js
node client.js

TypeScript uses Node.js networking underneath while adding static typing.


🐚 Shell / Bash

Click to open Shell guide

Folder

shell-files/
β”œβ”€β”€ server.sh
└── client.sh

Make Executable

chmod +x server.sh
chmod +x client.sh

Run

./server.sh
./client.sh

Depending on the implementation, networking utilities such as nc or Bash TCP streams may be required.


🐘 PHP

Click to open PHP guide

Folder

php-files/
β”œβ”€β”€ server.php
└── client.php

Run

php server.php
php client.php

PHP commonly uses stream socket APIs for TCP communication.


πŸ”΅ Go

Click to open Go guide

Folder

go-files/
β”œβ”€β”€ server.go
└── client.go

Run Server

go run server.go

Run Client

go run client.go

Main Package

net

Mapping

net.Listen()       β†’ bind + listen
listener.Accept()  β†’ accept
net.Dial()         β†’ connect
connection.Write() β†’ send
reader.ReadString() β†’ receive
connection.Close() β†’ close

πŸ¦€ Rust

Click to open Rust guide

Folder

rust-files/
β”œβ”€β”€ server.rs
└── client.rs

Compile

rustc server.rs
rustc client.rs

Run

Linux/macOS:

./server
./client

Windows:

server.exe
client.exe

Main Types

TcpListener
TcpStream
BufReader

πŸ’Ž Ruby

Click to open Ruby guide

Folder

ruby-files/
β”œβ”€β”€ server.rb
└── client.rb

Run

ruby server.rb
ruby client.rb

Main Classes

TCPServer
TCPSocket

🎯 Dart

Click to open Dart guide

Folder

dart-files/
β”œβ”€β”€ server.dart
└── client.dart

Run

dart run server.dart
dart run client.dart

Main Classes

ServerSocket
Socket

🟣 Kotlin

Click to open Kotlin guide

Folder

kotlin-files/
β”œβ”€β”€ Server.kt
└── Client.kt

Compile

kotlinc Server.kt -include-runtime -d Server.jar
kotlinc Client.kt -include-runtime -d Client.jar

Run

java -jar Server.jar
java -jar Client.jar

Kotlin uses Java networking classes such as:

ServerSocket
Socket

🐦 Swift

Click to open Swift guide

Folder

swift-files/
β”œβ”€β”€ server.swift
└── client.swift

Compile

swiftc server.swift -o server
swiftc client.swift -o client

Run

./server
./client

Swift networking support may depend on the operating system and installed SDK.


πŸŒ™ Lua

Click to open Lua guide

Folder

lua-files/
β”œβ”€β”€ server.lua
└── client.lua

Dependency

Install LuaSocket.

Run

lua server.lua
lua client.lua

Main Module

socket

πŸͺ Perl

Click to open Perl guide

Folder

perl-files/
β”œβ”€β”€ server.pl
└── client.pl

Run

perl server.pl
perl client.pl

Main Module

IO::Socket::INET

🟣 C#

Click to open C# guide

Folder

csharp-files/
β”œβ”€β”€ Server.cs
└── Client.cs

Recommended Method

Create a .NET console project:

dotnet new console

Replace Program.cs with the server or client code.

Run

dotnet run

Main Classes

TcpListener
TcpClient
NetworkStream
StreamReader
StreamWriter

πŸ§ͺ Example Chat

SERVER MACHINE                         CLIENT MACHINE

Server listening...                    Connecting...

Client connected!                      Connected!

                                      You: Hello Server
Client: Hello Server

You: Hello Client
                                      Server: Hello Client

                                      You: How are you?
Client: How are you?

You: Fine!
                                      Server: Fine!

You: bye
                                      Server ended the chat.

Connection closed.                    Connection closed.

πŸŽ“ What You Learn

By studying the same project in different languages, you can understand:

Networking Fundamentals
        β”‚
        β–Ό
Client-Server Architecture
        β”‚
        β–Ό
TCP Communication
        β”‚
        β–Ό
IP Address + Port
        β”‚
        β–Ό
Socket Lifecycle
        β”‚
        β”œβ”€β”€ Create
        β”œβ”€β”€ Bind
        β”œβ”€β”€ Listen
        β”œβ”€β”€ Accept
        β”œβ”€β”€ Connect
        β”œβ”€β”€ Send
        β”œβ”€β”€ Receive
        └── Close
        β”‚
        β–Ό
Cross-Language API Comparison

πŸ—ΊοΈ Learning Map

flowchart LR

    A["🌱 Beginner"] --> B["Understand IP + Port"]
    B --> C["Learn Client + Server"]
    C --> D["Learn TCP"]
    D --> E["Create Socket"]
    E --> F["Send + Receive"]
    F --> G["Infinite Chat"]
    G --> H["Two Machine Networking"]
    H --> I["Compare 17 Languages"]
    I --> J["πŸš€ Advanced Networking"]
Loading

⚠️ Important Notes

  • Always start the server before the client.
  • Change the client IP address before running on another machine.
  • Keep both machines reachable through the network.
  • Ensure port 5000 is not blocked.
  • Allow firewall access when required.
  • bye and quit terminate the chat.
  • Different languages may use different socket APIs, but the TCP lifecycle is the same.

⭐ Project Goal

Learn one networking concept deeply by implementing it in multiple programming languages.


🌐 Create β€’ Connect β€’ Communicate β€’ Repeat β€’ Close

About

TCP Socket Programming lifecycle implemented across 17 languages with client-server architecture & flowcharts. Built by Nitesh Chaurasiya.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages