One TCP Client-Server Infinite Chat project implemented across multiple programming languages to understand networking concepts, socket lifecycles, and cross-language communication.
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.
- 🌐 TCP/IP based communication
- 🖥️ Separate Server and Client programs
- 💬 Infinite message exchange
- 🔁 Continuous chat loop
- 🛑
byeorquitto 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
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#"]
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
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
| 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.
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
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/
Before running the project on two different machines:
Both devices should normally be connected to the same:
- Wi-Fi network
- LAN network
- Local router
On Windows:
ipconfigLook for:
IPv4 Address
Example:
192.168.1.10
Replace the default:
192.168.1.10
with the actual IPv4 address of the machine running the server.
Run the server on Machine 1.
Run the client on Machine 2.
If the connection fails, ensure the firewall allows TCP traffic on:
Port 5000
Dynamic reading tip: Each language is inside a collapsible section. Open only the language you want to study.
Click to open Python guide
python-files/
├── server.py
└── client.py
python server.pypython client.pysocketsocket()
bind()
listen()
accept()
connect()
send()
recv()
close()
- Server creates a TCP socket.
- Server binds to an IP address and port.
- Server listens for clients.
- Client creates a socket.
- Client connects to the server.
- Messages are exchanged continuously.
byeorquitcloses the chat.
Click to open Java guide
java-files/
├── Server.java
└── Client.java
javac Server.java
javac Client.javajava Serverjava ClientServerSocket
Socket
BufferedReader
PrintWriter
ServerSocket → bind + listen
accept() → accept client
Socket → connect
PrintWriter → send
BufferedReader → receive
close() → close
Click to open C guide
c-files/
├── server.c
└── client.c
gcc server.c -o server
gcc client.c -o client./server
./clientCompile with MinGW or another C compiler.
socket()
bind()
listen()
accept()
connect()
send()
recv()
close()
C provides one of the closest implementations to the original low-level socket API.
Click to open C++ guide
cpp-files/
├── server.cpp
└── client.cpp
g++ server.cpp -o server
g++ client.cpp -o client./server
./clientC++ generally uses the same low-level socket concepts as C, combined with C++ input/output features.
Click to open JavaScript guide
js-files/
├── server.js
└── client.js
node server.jsnode client.jsnet
net.createServer()
server.listen()
socket.connect()
socket.write()
data event
socket.end()
Click to open TypeScript guide
typescript-files/
├── server.ts
└── client.ts
npm install -g typescripttsc server.ts
tsc client.tsnode server.js
node client.jsTypeScript uses Node.js networking underneath while adding static typing.
Click to open Shell guide
shell-files/
├── server.sh
└── client.sh
chmod +x server.sh
chmod +x client.sh./server.sh
./client.shDepending on the implementation, networking utilities such as nc or Bash TCP streams may be required.
Click to open PHP guide
php-files/
├── server.php
└── client.php
php server.php
php client.phpPHP commonly uses stream socket APIs for TCP communication.
Click to open Go guide
go-files/
├── server.go
└── client.go
go run server.gogo run client.gonet
net.Listen() → bind + listen
listener.Accept() → accept
net.Dial() → connect
connection.Write() → send
reader.ReadString() → receive
connection.Close() → close
Click to open Rust guide
rust-files/
├── server.rs
└── client.rs
rustc server.rs
rustc client.rsLinux/macOS:
./server
./clientWindows:
server.exe
client.exeTcpListener
TcpStream
BufReader
Click to open Ruby guide
ruby-files/
├── server.rb
└── client.rb
ruby server.rb
ruby client.rbTCPServer
TCPSocket
Click to open Dart guide
dart-files/
├── server.dart
└── client.dart
dart run server.dart
dart run client.dartServerSocket
Socket
Click to open Kotlin guide
kotlin-files/
├── Server.kt
└── Client.kt
kotlinc Server.kt -include-runtime -d Server.jar
kotlinc Client.kt -include-runtime -d Client.jarjava -jar Server.jar
java -jar Client.jarKotlin uses Java networking classes such as:
ServerSocket
Socket
Click to open Swift guide
swift-files/
├── server.swift
└── client.swift
swiftc server.swift -o server
swiftc client.swift -o client./server
./clientSwift networking support may depend on the operating system and installed SDK.
Click to open Lua guide
lua-files/
├── server.lua
└── client.lua
Install LuaSocket.
lua server.lua
lua client.luasocket
Click to open Perl guide
perl-files/
├── server.pl
└── client.pl
perl server.pl
perl client.plIO::Socket::INET
Click to open C# guide
csharp-files/
├── Server.cs
└── Client.cs
Create a .NET console project:
dotnet new consoleReplace Program.cs with the server or client code.
dotnet runTcpListener
TcpClient
NetworkStream
StreamReader
StreamWriter
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.
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
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"]
- 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
5000is not blocked. - Allow firewall access when required.
byeandquitterminate the chat.- Different languages may use different socket APIs, but the TCP lifecycle is the same.