Network Programming Lab report
Network Programming Lab report
Objective: To understand the basics of how network traffic is captured and analyzed.
Steps:
1. Install Wireshark on a computer.
2. Open Wireshark and start a new capture on the active network interface.
3. Visit a few websites or use some networked applications to generate traffic.
4. Stop the capture after a few minutes.
5. Explore the captured packets, identify different types of traffic (HTTP, HTTPS, DNS, etc.), and
look at details like source and destination IP addresses, ports, and protocols used.
Steps:
1. Install Nmap
2. Open a terminal or command prompt.
3. Type the following command:
$ nmap 192.168.1.1 (type target IP address)
Scan Types:
Nmap offers various scan types, including:
• TCP Connect Scan (-sT): The default scan type that establishes a full TCP connection with
the target.
1
• SYN Stealth Scan (-sS): Also known as a SYN scan, it sends SYN packets to determine which
ports are open.
• UDP Scan (-sU): Scans for open UDP ports.
• OS Detection (-O): Attempts to determine the operating system of the target.
• Service Version Detection (-sV): Identifies the version of services running on open ports.
• Aggressive Scan (-A): Enables OS detection, version detection, script scanning, and
traceroute.
• Ping Scan (-sn): Checks if hosts are online without scanning ports.
Example Commands:
Scan a single
host: nmap
192.168.1.1
Scan a range of IP
addresses: nmap
192.168.1.1-100
Scan a subnet:
nmap 192.168.1.0/24
Security Considerations:
Permission: Depending on your environment, you may need appropriate permissions to perform
scans.
Legal Considerations: Ensure you have authorization before scanning networks that you don't own.
Firewall Rules: Scans may trigger intrusion detection systems or be blocked by firewalls.
Output:
2
3
LAB-2: NETWORK PROGRAMMING WITH JAVA: PRINTING THE IP ADDRESS
AND HOSTNAME OF A WEBSITE
Objective:
To understand the basics of network programming by writing a Java program that prints the
IP address and hostname of a website.
Program Code:
//Program to print the Ip address and hostname of a website
import java.io.IOException;
import java.net.InetAddress;
try {
InetAddress address = InetAddress.getByName("www.youtube.com");
System.out.println(address);
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
Output:
4
LAB-3: CREATING A NETWORK PROGRAMMING WITH JAVA: TESTING
CHARACTERISTICS OF AN IP ADDRESS.
Objective:
To create a java program to test and print various characteristics of an IP address using the
‘InetAddress’ class.
Program Code:
import java.net.InetAddress;
import java.net.UnknownHostException;
5
}
// Check if the multicast address is a site-wide multicast address
else if (address.isMCSiteLocal()) {
System.out.println(address + " is a site wide multicast address.");
}
// Check if the multicast address is a subnet-wide multicast address
else if (address.isMCLinkLocal()) {
System.out.println(address + " is a subnet wide multicast address.");
}
// Check if the multicast address is an interface-local multicast address
else if (address.isMCNodeLocal()) {
System.out.println(address + " is an interface-local multicast address.");
}
// If it's a multicast address but doesn't fit any specific type, print unknown type
else {
System.out.println(address + " is an unknown multicast address type.");
}
}
// Finally, if it is not multicast, it should be unicast
else {
System.out.println(address + " is a unicast address.");
}
} catch (UnknownHostException e) {
System.out.println("Could not resolver: " + args[0]);
}
}
}
Output:
C:\Users\Bibas Basnet\Desktop\NP>javac IpAddressTester.java
C:\Users\Bibas Basnet\Desktop\NP>java IpAddressTester 202.63.23.21
/202.63.23.21 is a global address.
/202.63.23.21 is a unicast address.
Conclusion:
This program takes an IP address as input and determines its type (wildcard, loopback, link-
local, site-local, global, multicast, or unicast), printing the results to the console.
6
LAB-4: CREATING A NETWORK PROGRAM: VERIFY IF TWO WEBSITE LINKS
POINTS TO THE SAME MACHINE.
Objective:
To create a java network program that retrieves and compares the IP addresses of two
specified website links.
Program Code:
import java.net.InetAddress;
import java.net.UnknownHostException;
if (firstHost.equals(secondHost)) {
System.out.println("provide two host are pointing to the same machine");
System.out.println("FirstHost:" + firstHost);
System.out.println("SecondHost" + secondHost);
}
else {
System.out.println("provide two host are not pointing to the same machine");
System.out.println("FirstHost:" + firstHost);
System.out.println("SecondHost" + secondHost);
}
}
catch (UnknownHostException unknownHostException) {
System.out.println("Host lookup failed.");
}
}
}
Output:
7
LAB-5: CREATING A NETWORK PROGRAM: IMPLEMENTING A SIMPLE
SPAM CHECKER.
Objectives:
To develop a Java network program that implements a simple spam checker to determine if a
website is classified as spam.
Program Code:
import java.net.InetAddress;
import java.net.UnknownHostException;
8
LAB 6: CREATING A NETWORK PROGRAM: CHECKING THE PROTOCOL OF
A URL.
Objective:
To create a program that identifiers and displays the protocol of a given URL.
Program Code:
import java.net.MalformedURLException;
import java.net.URL;
Output:
Conclusion:
This Program successfully identified and displayed URL protocols, improving our
understanding of URL parsing.
9
LAB 7: CREATING A NETWORK PROGRAM: SPLITTING A URL.
Objective:
To Create a java program to split a URL into its components.
Program Code:
import java.net.MalformedURLException;
import java.net.URL;
Conclusion:
This Program Parsed URLs into their individual parts
10
LAB 8: CREATING A NETWORK PROGRAM: RETRIEVING DATA FROM A
URL.
Objective:
To create a program that retrieves and displays data from a given URL.
Program Code:
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.MalformedURLException;
import java.net.URL;
11
Output:
<!doctype html>
<html itemscope="" itemtype="http://schema.org/WebPage" lang="en">
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<meta content="width=device-width,initial-scale=1" name="viewport">
<meta content="Google" property="og:site_name">
<meta content="Search the world's information, including webpages, images, videos
and more. Google has many special features to help you find exactly what you're
looking for." name="description">
<meta content="index,follow" name="robots"><meta
content="https://www.google.com/images/branding/googlelogo/2x/googlelogo_light_
color_272x92dp.png" property="og:image">
<meta content="Google" property="og:title">
<meta content="http://www.google.com/" property="og:url">
<meta content="Google" name="twitter:site">
<meta content="summary" name="twitter:card">
<meta content="Google" name="twitter:title">
<meta content="Search the world's information, including webpages, images, videos
and more. Google has many special features to help you find exactly what you're
looking for." name="twitter:description">
<meta
content="https://www.google.com/images/branding/googlelogo/2x/googlelogo_light_
color_272x92dp.png" name="twitter:image">
<title>Google</title>
<style>
body { margin: 0; font-family: Arial, sans-serif; }
#searchform { margin: 20px; }
input[type="text"] { width: 300px; height: 30px; }
input[type="submit"] { height: 36px; }
</style>
</head>
<body>
<form id="searchform" action="/search" method="get">
<input type="text" name="q" aria-label="Search">
<input type="submit" value="Google Search">
</form>
</body>
</html>
Conclusion:
This Program successfully created a program to fetch and display data from a URL,
enhancing our skills in network data retrieval.
12
LAB 9: CREATING A NETWORK PROGRAM: SPLITTING URI.
Objective:
To Split a URI into its components.
Program Code:
import java.net.URI;
import java.net.URISyntaxException;
public class SplittingUri {
public static void main(String[] args) {
try{
URI uri = new
URI("https://admin:[email protected]:8080/path/content/profile.php?q='Ram'#3
hxcf");
System.out.println("Scheme: " + uri.getScheme());
System.out.println("User info: " + uri.getUserInfo());
System.out.println("Authority: " + uri.getAuthority());
System.out.println("Host: " + uri.getHost());
System.out.println("Port: " + (uri.getPort() == -1 ? "Default" : uri.getPort()));
System.out.println("Path: " + uri.getPath());
System.out.println("Query: " + uri.getQuery());
System.out.println("Fragment: " + uri.getFragment());
}catch(URISyntaxException uriSyntaxException){
System.err.println(uriSyntaxException);
}}}
Output:
PS C:\Users\Bibas Basnet\Desktop\NP> javac SplittingUri.java
PS C:\Users\Bibas Basnet\Desktop\NP> java SplittingUri
https://admin:[email protected]:8080/path/content/profile.php?q='Ram'#3hxcf
Scheme: https
User info: admin: pass1234
Authority: admin:[email protected]:8080
Host: www.example.com
Port: 8080
Path: /path/content/profile.php
Query: q='Ram'
Fragment: 3hxcf
Conclusion:
This program split URIs into their individual parts, enhancing our understanding of URI
structure and parsing.
13
LAB 10: IMPLEMENTING A NETWORK PROGRAM: DEMONSTRATING X-
WWW-FORM- URLENCODED STRING HANDLING.
Objective:
To handle x-www-form-urlencoded strings by encoding and decoding form data in a
network program.
Program Code:
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
14
StringBuilder decodedData = new StringBuilder();
for (String pair : pairs) {
int idx = pair.indexOf("=");
String key = URLDecoder.decode(pair.substring(0, idx),
StandardCharsets.UTF_8.toString());
String value = URLDecoder.decode(pair.substring(idx + 1),
StandardCharsets.UTF_8.toString());
if (decodedData.length() > 0) {
decodedData.append("&");
}
decodedData.append(key).append("=").append(value);
}
return decodedData.toString();
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
}
Output:
Conclusion:
15
LAB 11: BUILDING A NETWORK PROGRAM: DEMONSTRATING URL
ENCODING AND DECODING FUNCTIONALITY.
Objective:
To demonstrate URL encoding and decoding functionality in a network program.
Program Code:
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
Output:
Conclusion:
This program effectively encodes and decodes URLs, illustrating the handling of special
characters in web addresses.
16
LAB 12: EXPLORING SERVER-SIDE COMMUNICATION: UNIVERSITIES
SEARCH BY COUNTRY NAME PROGRAM.
Objective:
To demonstrate how to search for universities by country using server-side
communication.
Program Code:
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
int c;
while ((c = fetchedResult.read()) != -1) {
System.out.print((char) c);
}
}catch(UnsupportedEncodingException unsupportedEncodingException){
System.err.println(unsupportedEncodingException);
}catch(MalformedURLException malformedURLException){
System.err.println(malformedURLException);
}catch(IOException ioException){
System.err.println(ioException);
}}}
17
Output:
Conclusion:
This program successfully retrieves and displays a list of universities for a given country,
illustrating effective use of server-side data retrieval.
18
LAB 13: CREATING A NETWORK PROGRAM: TESTING HTTP REQUESTS BY
SENDING RAW REQUEST MESSAGES TO AN HTTP SERVER.
Objective:
To test HTTP requests by sending raw request messages to an HTTP server and observing
responses.
Program Code:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
try {
// Create a TCP socket and connect to the host:port
Socket socket = new Socket(host, port);
// Create the input and output streams for the network socket
BufferedReader bufferedReader = new BufferedReader(new
InputStreamReader(socket.getInputStream()));
PrintWriter printWriter = new PrintWriter(socket.getOutputStream(), true);
String line;
while ((line = bufferedReader.readLine()) != null) {
System.out.println(line);
}
bufferedReader.close();
printWriter.close();
socket.close();
} catch (IOException ioException) {
System.err.println(ioException);
}
}}
19
Output:
Conclusion:
The program effectively demonstrates how to send and receive raw HTTP requests and
responses, validating HTTP communication with a server.
20
LAB 14: CREATING A NETWORK PROGRAM: READING DATA FROM A
SERVER.
Objective:
To test HTTP requests by sending raw request messages to an HTTP server and
observing responses.
Program Code:
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
int content;
while ((content = reader.read()) != -1) {
System.out.print((char) content);
}
} catch (MalformedURLException malformedURLException) {
System.out.println("https://google.com is not a parseable URL.");
} catch (IOException ioException) {
System.err.println(ioException);
}
}
}
21
Compile and Run:
Expected Output:
<!doctype html>
<html itemscope="" itemtype="http://schema.org/WebPage" lang="en">
<head>
<meta content="Search the world's information, including webpages, images, videos
and more. Google has many special features to help you find exactly what you're
looking for." name="description">
<meta content="noodp" name="robots">
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<link href="/images/branding/product/ico/googleg_lodp.ico" rel="shortcut icon">
<title>Google</title>
<! -- Additional meta tags and scripts -->
</head>
<body>
<div id="main">
<! -- Content of the Google homepage -->
<div class="content">
<h1>Welcome to Google</h1>
<p>This is a simulated output of the Google homepage HTML content. </p>
<form action="/search" method="get">
<input type="text" name="q" placeholder="Search Google">
<button type="submit">Search</button>
</form>
<!-- Additional elements -->
</div>
</div>
<script>
// JavaScript code
console.log ('This is a simulated output');
</script>
</body>
</html>
Conclusion:
This program demonstrates how to fetch and read data from a server using Java,
showcasing network communication capabilities.
22
LAB 15: CREATING A NETWORK PROGRAM: PARSING MIME HEADERS.
Objective:
Program Code:
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
23
Output:
Conclusion:
The program effectively extracts and displays MIME headers, demonstrating the ability to
handle HTTP responses and parse header information.
24
LAB 16: CREATING A NETWORK PROGRAM: RETRIEVING SOCKET
INFORMATION.
Objective:
To retrieve and display socket information using a java network program.
Program Code:
import java.net.*;
import java.io.*;
Output:
Conclusion:
25
LAB 17: CREATING A NETWORK PROGRAM: WRITING TO SERVERS USING
SOCKETS.
Objective:
To develop a Java network program that writes data to a server using sockets.
Program Code:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
try {
// Connect to the DICT server
Socket socket = new Socket(hostname, port);
26
}
}
Output:
gold
adj 1: made from or covered with gold; "gold coins"; "the gold dome of the Capitol"; "the
golden calf"; "gilded icons"
2: having the deep slightly brownish color of gold; "long aureate (or golden) hair"; "a gold
carpet" [syn: {aureate}, {gilded}, {gilt}, {gold}, {golden}]
2: a deep yellow color; "an amber light illuminated the room"; "he admired the gold of her hair"
[syn: {amber}, {gold}]
3: a soft yellow malleable ductile (trivalent and univalent) metallic element; occurs mainly as
nuggets in rocks and alluvial deposits; does not react with most chemicals but is attacked by
chlorine and aqua regia [syn: {gold}, {Au}, {atomic number 79}]
4: great wealth; "Whilst that for which all virtue now is sold, and almost every vice--almighty
gold"--Ben Jonson
5: something likened to the metal in brightness or preciousness or superiority etc.; "the child
was as good as gold"; "she has a heart of gold"
Conclusion:
The program demonstrates sending a command to a server and receiving a response via sockets.
27
LAB 18: BUILDING A COMMAND LINE WHOIS CLIENT.
Objective:
To build a command line WHOIS client using Java to query domain information.
Program Code:
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Scanner;
} catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
}
Output:
28
Domain Name: GOOGLE.COM
DNSSEC: unsigned
Conclusion:
The program successfully retrieves WHOIS data for a domain via the command line.
29
LAB 19: CREATING A MULTITHREADED DAYTIME SERVER USING
SERVERSOCKET.
Objective:
To create a multithreaded daytime server using ServerSocket.
Program Code:
MultithreadedDaytimeServer.java
import java.net.*;
import java.io.*;
import java.util.Date;
DaytimeThread(Socket connection) {
this.connection = connection;
}
@Override
public void run() {
try (Writer out = new OutputStreamWriter(connection.getOutputStream())) {
Date now = new Date();
30
out.write(now.toString() + "\r\n");
out.flush();
} catch (IOException ex) {
System.err.println("Error handling client: " + ex.getMessage());
} finally {
try {
connection.close();
} catch (IOException e) {
// Ignore exception on close
}}}}}
MultiThreadClient.java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;
} catch (IOException e) {
System.err.println("Error: " + e.getMessage());
}}}
Output:
Conclusion:
This program handles multiple client requests simultaneously by creating a new thread for each
connection, ensuring efficient and concurrent processing.
31
LAB 20: CREATING A PROGRAM TO READ A TEXT FILE USING NIO.
Objective:
To create a Program to read a text file using NIO for efficient file handling.
Program Code:
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
Output:
C:\Users\Bibas Basnet\Desktop\NP\NonblockingIO> javac FileChannelDemo.java
C:\Users\Bibas Basnet\Desktop\NP\NonblockingIO> java FileChannelDemo
Hello World!
This is a testfile.
Conclusion:
A Java NIO program reads a text file efficiently using `FileChannel` and `ByteBuffer`.
32
LAB 21: CREATING A PROGRAM TO SEND DATA USING JAVA NIO SOCKET
CHANNEL.
Objective:
Program Code:
SocketChannelClient.java
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.SocketChannel;
import java.nio.file.Path;
import java.nio.file.Paths;
// Read the file and send its contents through the socket channel
while (fileChannel.read(buffer) > 0) {
buffer.flip(); // Switch buffer from writing mode to reading mode
client.write(buffer); // Write buffer content to the socket channel
buffer.clear(); // Clear the buffer for the next read
}
System.out.println("File Sent");
}
}
33
SocketChannelServer.java
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.EnumSet;
System.out.println("File Received");
}
34
}
Output:
Conclusion:
This program sends data efficiently using Java NIO's `SocketChannel` with non-blocking I/O.
35
LAB 22: DEVELOPING A UDP ECHO SERVER AND CLIENT PROGRAM.
Objective:
To develop a UDP Echo Server and Client for message exchange using the UDP protocol.
Program Code:
UDPEchoClient.java
package UDP;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.util.Scanner;
public class UDPEchoClient {
public static void main(String[] args) {
DatagramSocket socket = null;
Scanner scanner = new Scanner(System.in);
try {
// Create a DatagramSocket
socket = new DatagramSocket();
InetAddress serverAddress = InetAddress.getByName("localhost");
int serverPort = 2000; // Replace with server port
while (true) {
// Read user input
System.out.print("Enter message to send: ");
String message = scanner.nextLine();
// Send the message to the server
byte[] data = message.getBytes();
DatagramPacket packet = new DatagramPacket(data, data.length, serverAddress,
serverPort);
socket.send(packet);
// Prepare a DatagramPacket to receive the echo response
byte[] buffer = new byte[256];
DatagramPacket responsePacket = new DatagramPacket(buffer, buffer.length);
socket.receive(responsePacket);
// Print the received response
String receivedMessage = new String(responsePacket.getData(), 0,
responsePacket.getLength());
System.out.println("Received echo: " + receivedMessage);
// Optionally exit on specific input
36
if (message.equalsIgnoreCase("exit")) {
break; } }
} catch (Exception e) {
e.printStackTrace();
} finally {
if (socket != null && !socket.isClosed()) {
socket.close();
}
scanner.close(); }}}
UDPEchoServer.java
package UDP;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
public class UDPEchoServer {
public static void main(String[] args) {
DatagramSocket socket = null;
try {
// Create a DatagramSocket and bind it to port 2000
socket = new DatagramSocket(2000);
System.out.println("UDP Echo Server is running on port 2000...");
while (true) {
// Receive a packet
socket.receive(packet);
37
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (socket != null && !socket.isClosed()) {
socket.close();
}
}
}
}
Output:
C:\Users\Bibas Basnet\Desktop\NP\UDP> javac UDPEchoClient.java
C:\Users\Bibas Basnet\Desktop\NP\UDP> javac UDPEchoServer.java
C:\Users\Bibas Basnet\Desktop\NP\UDP> java UDPEchoServer
UDP Echo Server is running on port 2000...
Received: Hello! what is your name?
Sent back: Hello! what is your name?
Conclusion:
we implemented a UDP Echo Server and Client to demonstrate simple, fast, connectionless
communication using UDP.
38
LAB 23: CREATING A PROGRAM TO SEND DATA USING JAVA NIO
DATAGRAM SOCKET.
Objective:
To create a program to Send Data using Java NIO Datagram Socket.
Program Code:
DatagramChannelUDPServer.java
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.DatagramChannel;
39
// Send the response to the client
channel.send(responseBuffer, clientAddress);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
DatagramChannelUDPClient.java
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.DatagramChannel;
import java.util.Scanner;
// Server address
InetSocketAddress serverAddress = new InetSocketAddress("localhost", 2000);
buffer.clear();
buffer.put(message.getBytes());
buffer.flip();
if (message.equalsIgnoreCase("exit")) {
break;
}
40
// Receive response from the server
responseBuffer.clear();
channel.receive(responseBuffer);
responseBuffer.flip();
byte[] data = new byte[responseBuffer.remaining()];
responseBuffer.get(data);
String response = new String(data);
Output:
C:\Users\Bibas Basnet\Desktop\NP\UDP> javac DatagramChannelUDPClient.java
C:\Users\Bibas Basnet\Desktop\NP\UDP> javac DatagramChannelUDPServer.java
C:\Users\Bibas Basnet\Desktop\NP\UDP> java DatagramChannelUDPServer
UDP Echo Server is running on port 2000...
Received: Hello world!
Sent back: Hello world!
Received: Bye World!
Sent back: Bye World!
C:\Users\Bibas Basnet\Desktop\NP\UDP> java DatagramChannelUDPClient
Enter message to send: Hello world!
Server response: Hello world!
Server response: Bye World!
Conclusion:
This program use Java NIO to send data through a Datagram Socket, demonstrating non-
blocking network communication and efficient data transmission using the UDP protocol.
41
LAB 24: IMPLEMENTING BASIC TEXT MESSAGING BETWEEN CLIENT AND
SERVER USING RMI.
Objective:
To implement basic text messaging between a client and server using Java RMI to demonstrate
remote communication and method invocation across a network.
These are the steps to be followed sequentially to implement Interface as defined below as follows:
Program Code:
import java.rmi.Remote;
import java.rmi.RemoteException;
Program Code:
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
42
Program Code:
import java.rmi.Naming;
import java.rmi.registry.LocateRegistry;
Program Code:
import java.rmi.Naming;
43
Step-6: Compile and Run
Compile the Code: Compile all Java files including the interface, implementation,
server, and client.
Start the RMI Registry: Run rmi registry in a separate terminal window.
Run the Server: Execute the server program to register the remote object.
Run the Client: Execute the client program to interact with the remote object
Output:
Conclusion:
This program demonstrates basic text messaging in network programming using Java RMI,
enabling communication between a client and server over a network.
44