π Developing TCP/IP Client and Server with Telnet (Java Networking)
Visual ReferenceInternet Protocol Suite Wikipedia
π· 1. Definition
πΉ TCP/IP Client-Server Model
A TCP/IP client-server system is a network communication model where:
Client sends request
Server listens and responds
Communication happens using TCP
π TCP ensures:
Reliable communication
Ordered data delivery
Error checking
πΉ Telnet
Telnet is a network protocol and tool used to:
Connect to remote servers
Test TCP connections manually
Send simple text-based commands
π It works on port 23 (default)
π· 2. Purpose of TCP/IP Client-Server
Build network applications
Enable communication between systems
Exchange data over internet or LAN
Used in chat apps, file transfer, remote services
π· 3. TCP Client-Server Architecture
Visual ReferenceClientβServer Wikipedia
π Diagram Description:
Client β TCP Socket β Network β Server Socket β Server Process
Response flows back similarly
π· 4. Key Classes in Java
Class
Purpose
Socket
Client-side connection
ServerSocket
Server-side listening
InputStream
Receive data
OutputStream
Send data
π· 5. Steps to Create TCP Server
β Step-by-step:
Create ServerSocket
Wait for client connection (accept())
Read data from client
Send response
Close connection
πΉ TCP Server Example
import java.net.*;
import java.io.*;
public class TCPServer {
public static void main (String[] args) throws Exception {
ServerSocket serverSocket = new ServerSocket (5000 );
System.out.println("Server started... Waiting for client" );
Socket socket = serverSocket.accept();
BufferedReader in = new BufferedReader (
new InputStreamReader (socket.getInputStream()));
String msg = in.readLine();
System.out.println("Client says: " + msg);
serverSocket.close();
}
}
π· 6. Steps to Create TCP Client
β Step-by-step:
Create Socket
Connect to server
Send message
Close connection
πΉ TCP Client Example
import java.net.*;
import java.io.*;
public class TCPClient {
public static void main (String[] args) throws Exception {
Socket socket = new Socket ("localhost" , 5000 );
PrintWriter out = new PrintWriter (socket.getOutputStream(), true );
out.println("Hello Server" );
socket.close();
}
}
π· 7. Using Telnet for TCP Testing
πΉ What Telnet Does
Telnet can act as a simple TCP client to:
Connect to server
Send raw text data
Test port connectivity
πΉ Command Example
telnet localhost 5000
π This connects to server running on port 5000
πΉ What Happens:
Telnet opens TCP connection
User types message
Server receives message
Server responds (if programmed)
π· 8. TCP Communication Flow
π Flow:
Server starts (listening)
Client connects (Socket)
Data exchange happens
Connection closed
π· 9. Features of TCP
Reliable communication
Connection-oriented
Error checking
Data delivered in order
π· 10. TCP vs UDP (Important)
Feature
TCP
UDP
Reliability
High
Low
Speed
Slower
Faster
Connection
Yes
No
Example
Web, Telnet
Streaming
π· 11. Advantages of TCP Client-Server
Reliable communication
Easy to implement in Java
Supports multiple clients
Widely used in real systems
π· 12. Disadvantages
Slower due to overhead
Requires connection setup
Not suitable for real-time systems
π· 13. Important Rules
Server must run before client
Ports must match
Always close sockets
Handle exceptions properly
Use correct port numbers (>1024 recommended)
π· 14. Diagram Description (Exam Tip)
π TCP Client-Server Model:
Client (Socket)
β Request β ServerSocket
β Server processes request
β Response β Client
Telnet can replace client in testing phase
π Likely Exam Questions
What is TCP/IP client-server model?
Explain TCP server program in Java.
Write a TCP client program.
What is the role of ServerSocket?
What is Telnet used for?
Explain TCP communication flow.
Difference between TCP and UDP.
How does Telnet work with TCP?
Advantages of TCP programming.
Explain socket programming in Java.
π Quick Revision Summary
TCP = reliable connection-based protocol
Client uses Socket
Server uses ServerSocket
Data is exchanged using streams
Telnet = tool to test TCP connections
Communication is bidirectional and reliable