Advanced Java Programming · Unit 7
Network Programming with Sockets
Exam-focused notes for Network Programming with Sockets (Advanced Java Programming, BIT401): what the TU syllabus asks and how it has actually been tested, with 5 solved past questions from this unit.
What this unit covers
- TCP socket programming steps
- UDP socket programming steps
- Client-server communication
- Port usage and significance
- Socket creation and connection
- Data transmission over sockets
TCP socket programming steps
Mention the steps to write the socket program using TCP. [5]
Since reference notes are not provided, this answer follows standard TCP socket programming methodology taught in BSc CSIT curricula: 1. Create a Socket - Use socket() system call to create a socket with domain (AFINET), type (SOCKSTREAM), and protocol (0 o...
Full solved answer →Write a socket program using TCP where client sends an integer to server and server response whether it is positive or negative. [5]
A TCP client-server program where: - Client: Connects to server and sends an integer - Server: Receives integer, determines if positive/negative, sends response back --- --- --- 1. Compile both programs: 2. Run server (Terminal 1): 3. Run client (Terminal 2...
Full solved answer →Write down a java program where client sends a number to server and server calculates its factorial and sends it back to client using TCP. [5]
Here is a complete Java program demonstrating client-server communication using TCP sockets for factorial calculation: 1. ServerSocket: Listens on port 5000 for incoming client connections 2. Socket: Establishes connection between client and server 3. Print...
Full solved answer →UDP socket programming steps
Write the steps of writing socket program using UDP. [5]
UDP (User Datagram Protocol) is a connectionless, unreliable transport layer protocol. The following are the steps to write a UDP socket program: 1. Create a socket - Use socket() system call with parameters: AFINET (address family), SOCKDGRAM (socket type ...
Full solved answer →Port usage and significance
Why do we need ports in socket programming? What types of instructions are written in try block? [5]
Ports serve the following critical purposes: 1. Process Identification: Ports uniquely identify specific processes or services running on a host machine. Since a single computer can run multiple network applications simultaneously, ports distinguish between...
Full solved answer →Make Unit 7 stick
Practice BIT401 with flashcards & quizzes