Skip to content

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

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages