Feedback Form

Introduction to Client-Server Architecture: TCP/IP, Sockets, and Ports

Introduction to Client-Server Architecture: TCP/IP, Sockets, and Ports

Client-Server Architecture क्या है?

Client-Server Architecture एक ऐसा communication model है जिसमें दो मुख्य components होते हैं — Client और Server। Client वह system या application होता है जो request भेजता है, जबकि Server वह system होता है जो उन requests को process करके response वापस भेजता है। यह model आज की हर modern application, जैसे — web apps, mobile apps, और cloud systems की foundation है।

Client-Server Architecture का सबसे बड़ा फायदा यह है कि इससे data centralized रहता है और management आसान हो जाता है। Client सिर्फ user interface संभालता है, जबकि Server actual logic और data storage manage करता है। इस separation की वजह से scalability और performance दोनों बढ़ जाते हैं।

Client-Server Model कैसे काम करता है?

जब भी कोई user किसी web page को open करता है, वह client के ज़रिए server को request भेजता है। Server उस request को process करता है और suitable response (जैसे HTML page या JSON data) वापस भेज देता है। यह पूरी process network के माध्यम से होती है, जो TCP/IP जैसे protocols का use करती है।

  • Client: Request भेजने वाला system या software (जैसे browser, mobile app)
  • Server: Response देने वाला system (जैसे web server, database server)
  • Network: Medium जिसके द्वारा Client और Server एक-दूसरे से communicate करते हैं

TCP/IP Protocol क्या है?

TCP/IP का full form है Transmission Control Protocol / Internet Protocol। यह Internet और network communication का base protocol है। TCP/IP का काम यह सुनिश्चित करना है कि data packets सही तरीके से source से destination तक पहुंचें, और बीच में कोई data loss न हो।

TCP/IP के मुख्य Layers

TCP/IP architecture को चार layers में divide किया गया है। हर layer का अपना specific role होता है, जिससे data transmission smooth रहता है।

Layer Name Function Example Protocols
Application Layer User level services provide करती है HTTP, FTP, SMTP, DNS
Transport Layer Data delivery और reliability ensure करती है TCP, UDP
Internet Layer Data packets को routing और addressing provide करती है IP, ICMP
Network Access Layer Physical network communication handle करती है Ethernet, ARP

TCP vs UDP

TCP और UDP दोनों transport layer के protocols हैं, लेकिन इनका काम करने का तरीका अलग होता है।

Feature TCP UDP
Connection Type Connection-Oriented Connectionless
Reliability Reliable – data loss नहीं होता Unreliable – data loss हो सकता है
Speed Slower Faster
Use Case Web apps, email Streaming, gaming

Sockets क्या होते हैं?

Socket एक communication endpoint होता है जो Client और Server के बीच data exchange के लिए use किया जाता है। यह TCP/IP protocol पर आधारित होता है और programming के ज़रिए applications को network पर बात करने की ability देता है।

Socket का Basic Concept

हर socket एक combination होता है — IP address + Port number का। जब भी कोई client किसी server से connect होना चाहता है, वह server के IP और Port को target करता है। Server side पर socket connection accept करता है और दोनों systems के बीच data transfer शुरू होता है।

  • Server Socket: Connection को listen करने के लिए responsible होता है।
  • Client Socket: Connection request भेजता है और response receive करता है।

Socket Communication का Flow

Socket communication के steps इस प्रकार हैं:

  • Server एक socket create करता है और उसे किसी specific port पर bind करता है।
  • Server socket connection requests को listen करता है।
  • Client एक socket बनाता है और server के IP और port पर connect करता है।
  • Connection establish होने के बाद दोनों data send और receive करते हैं।

Java में Socket Programming का Example

नीचे एक simple Java socket communication example दिया गया है जो client-server interaction को दिखाता है।

// Server Side import java.io.*; import java.net.*; class Server { public static void main(String[] args) throws IOException { ServerSocket server = new ServerSocket(5000); Socket socket = server.accept(); DataInputStream input = new DataInputStream(socket.getInputStream()); String message = input.readUTF(); System.out.println("Client says: " + message); server.close(); } } // Client Side import java.io.*; import java.net.*; class Client { public static void main(String[] args) throws IOException { Socket socket = new Socket("localhost", 5000); DataOutputStream output = new DataOutputStream(socket.getOutputStream()); output.writeUTF("Hello Server!"); socket.close(); } }

Ports क्या होते हैं?

Port एक logical endpoint होता है जिसका use network communication के लिए किया जाता है। जब भी कोई server किसी service को provide करता है, वह उसे एक specific port number पर चलाता है। इससे client को पता रहता है कि किस service से connect होना है।

Port Numbers की Range

Port numbers 0 से 65535 तक होते हैं, और इन्हें तीन categories में divide किया गया है:

Port Range Type Example
0–1023 Well-Known Ports HTTP (80), HTTPS (443), FTP (21)
1024–49151 Registered Ports MySQL (3306), PostgreSQL (5432)
49152–65535 Dynamic / Private Ports Temporary client connections

Ports का Importance

Ports का main purpose यह होता है कि एक server पर multiple services parallel चल सकें। जैसे — HTTP port 80 पर चलता है, HTTPS port 443 पर, और FTP port 21 पर। इस तरह client को सही service तक पहुंचना आसान हो जाता है।

Client-Server Architecture के फायदे

  • Centralized Data Management: Server data को control करता है, जिससे security बढ़ती है।
  • Scalability: Server को upgrade करके system capacity बढ़ाई जा सकती है।
  • Maintenance: Server में changes करने से सभी clients update हो जाते हैं।
  • Performance: Client और Server दोनों अपनी-अपनी responsibilities efficiently handle करते हैं।

Client-Server Architecture के Real-life Applications

  • Web Browsing: Browser client होता है और web server responses देता है।
  • Email Communication: SMTP, IMAP जैसे servers और clients interaction करते हैं।
  • Online Banking: Secure server-side processing होता है।
  • Gaming Servers: Multiplayer games में real-time data exchange होता है।

Quick Summary Notes for Students

  • Client-Server Architecture में Client request भेजता है और Server response देता है।
  • TCP/IP data transmission का base protocol है।
  • Socket = IP Address + Port Number।
  • Ports services को identify करते हैं, जैसे HTTP (80), HTTPS (443)।
  • TCP reliable communication देता है जबकि UDP fast लेकिन unreliable होता है।
  • Server central point होता है जो resources manage करता है।
  • Client-Server model modern networking और web systems की backbone है।