🌐 Developing TCP/IP Client and Server with Telnet (Java Networking)
🔷 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
📊 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