ScholarQuill logoScholarQuillUniversity Notes
  • Notes
  • Past Papers
  • Blogs
  • Todo
Login
ScholarQuill logoScholarQuillUniversity Notes
Login
NotesPast PapersBlogsTodo
More
SubjectsDiscussionCGPA CalculatorGPA CalculatorStudent PortalCourse Outline
About
About usPrivacy PolicyReportContact
Notes
Past Papers
Blogs
Todo
Analytics
    Current Subject
    🧩
    Advanced Computer Programming
    COMP3114
    Progress0 / 12 topics
    Topics
    1. Java API: Abstract classes and Interfaces2. Packages and Exception handling3. Advanced issues of GUI and event handling4. Applets and Swing5. Network Programming Concepts: JDBC6. Multithreading7. Building Client/Server and implementing protocols8. RMI (Remote Method Invocation)9. Java Secure Socket Extension and Secure Sockets Layer (SSL)10. SSL Socket and SSL Server Socket classes11. Client and Server Authentication: HTTPS12. Developing TCP/IP client and server with telnet
    COMP3114›Developing TCP/IP client and server with telnet
    Advanced Computer ProgrammingTopic 12 of 12

    Developing TCP/IP client and server with telnet

    4 minread
    595words
    Beginnerlevel

    🌐 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:

    1. Create ServerSocket
    2. Wait for client connection (accept())
    3. Read data from client
    4. Send response
    5. 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:

    1. Create Socket
    2. Connect to server
    3. Send message
    4. 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:

    1. Telnet opens TCP connection
    2. User types message
    3. Server receives message
    4. Server responds (if programmed)

    🔷 8. TCP Communication Flow

    📊 Flow:

    1. Server starts (listening)
    2. Client connects (Socket)
    3. Data exchange happens
    4. 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

    1. What is TCP/IP client-server model?
    2. Explain TCP server program in Java.
    3. Write a TCP client program.
    4. What is the role of ServerSocket?
    5. What is Telnet used for?
    6. Explain TCP communication flow.
    7. Difference between TCP and UDP.
    8. How does Telnet work with TCP?
    9. Advantages of TCP programming.
    10. 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

    Previous topic 11
    Client and Server Authentication: HTTPS

    Past Papers

    Open this section to load past papers

    Click on Show Past Papers to see past papers.
    On This Page
      Reading Stats
      Est. reading time4 min
      Word count595
      Code examples0
      DifficultyBeginner