DCCN 6 To 9
DCCN 6 To 9
SCIENCE
EX. NO: 6
INSTALLATION AND CONFIGURE THE NET ANIM
DATE:
AIM:
1. Install Mercurial
4. To view the animation on NetAnim compile the code with NET ANIM.
b. Move the example code to the scratch folder and make the changes required for NetAnim,as
shown above.
c. Now cd to the scratch folder (cd ~/ns-allinone-3.24/ns-3.24/scratch/).
6. To visualize on NetAnim:
717822I153 – SENBAGAVALLI N
DEPARTMENT OF ARTIFICIAL INTELLIGENCE AND DATA 21ID15-DATA COMMUNICATION AND COMPUTER NETWORKS
SCIENCE
PROGRAM:
# Create four nodes set n0 [$ns node] set n1 [$ns node] set n2 [$ns node] set n3 [$ns node]
# Create links between the nodes
$ns duplex-link $n0 $n2 2Mb 10ms DropTail
$ns duplex-link $n1 $n2 2Mb 10ms DropTail ns duplex-link $n2 $n3 1.7Mb 20ms DropTail
717822I153 – SENBAGAVALLI N
DEPARTMENT OF ARTIFICIAL INTELLIGENCE AND DATA 21ID15-DATA COMMUNICATION AND COMPUTER NETWORKS
SCIENCE
# Setup a UDP connection set udp [new Agent/UDP] $ns attach-agent $n1
$udp set null [new Agent/Null]
717822I153 – SENBAGAVALLI N
DEPARTMENT OF ARTIFICIAL INTELLIGENCE AND DATA 21ID15-DATA COMMUNICATION AND COMPUTER NETWORKS
SCIENCE
$ns run
OUTPUT:
PREPARATION 30
LAB PERFOMANCE 30
REPORT 40
TOTAL 100
RESULT:
Thus, the program for Network Simulator Program to install and configure NET ANIM has been
executed successfully and its output is verified.
717822I153 – SENBAGAVALLI N
DEPARTMENT OF ARTIFICIAL INTELLIGENCE AND DATA 21ID15-DATA COMMUNICATION AND COMPUTER NETWORKS
SCIENCE
AIM:
To implement transmission control protocol and user datagram protocol using Java.
ALGORITHM:
1. Server Setup:
o Create a ServerSocket on a specified port.
o Accept incoming client connections using accept() method.
o Create input and output streams for communication.
2. Client Setup:
o Create a Socket with the server's IP address and port.
o Initialize input and output streams for data exchange.
3. Data Exchange:
o Client sends data to server using output stream.
o Server receives data from client using input stream.
o Optionally, server responds to client requests.
4. Loop:
o Repeat data exchange until termination condition is met (e.g., client closes connection).
5. Cleanup:
o Close input/output streams and sockets after communication ends.
PROGRAM:
Sender.java
import java.io.*;
import java.net.*;
import java.util.Scanner;
public class sender {
public static void main(String args[])
{
int p=9000,i,q=8000;
String h="localhost";
try
{
Scanner scanner = new Scanner(System.in);
System.out.print("Enter number of frames : ");
int number = scanner.nextInt();
if(number==0)
{
System.out.println("No frame is sent");
}
else
{
Socket s2;
s2= new Socket(h,q);
717822I153 – SENBAGAVALLI N
DEPARTMENT OF ARTIFICIAL INTELLIGENCE AND DATA 21ID15-DATA COMMUNICATION AND COMPUTER NETWORKS
SCIENCE
OUTPUT:
717822I153 – SENBAGAVALLI N
DEPARTMENT OF ARTIFICIAL INTELLIGENCE AND DATA 21ID15-DATA COMMUNICATION AND COMPUTER NETWORKS
SCIENCE
Reciever.java
import java.io.*;
import java.net.*;
import java.util.*;
717822I153 – SENBAGAVALLI N
DEPARTMENT OF ARTIFICIAL INTELLIGENCE AND DATA 21ID15-DATA COMMUNICATION AND COMPUTER NETWORKS
SCIENCE
PREPARATION 30
LAB PERFOMANCE 30
REPORT 40
TOTAL 100
RESULT:
Thus, the implementation of transmission control protocol and user datagram protocol using Java is done
successfully.
717822I153 – SENBAGAVALLI N
DEPARTMENT OF ARTIFICIAL INTELLIGENCE AND DATA 21ID15-DATA COMMUNICATION AND COMPUTER NETWORKS
SCIENCE
EX. NO: 7B
IMPLEMENTATION OF TRANSMISSION CONTROL PROTOCOL AND USER
DATE: DATAGRAM PROTOCOL
AIM:
To implement transmission control protocol and user datagram protocol using Java.
ALGORITHM:
1. Server Setup:
a. Get ready to listen for messages on a specific phone line (port).
b. Keep an ear out for incoming messages.
2. Client Setup:
a. Get ready to send messages.
b. Know who you want to send the message to (server's address) and on which "phone line" (port).
3. Sending and Receiving Messages:
a. Clients send messages to the server.
b. Servers listen for messages and receive them from clients.
4. Continual Communication:
a. Both clients and server can keep sending messages back and forth as needed.
5. Handling Errors:
a. If something goes wrong (like a message doesn't get through), figure out what happened and try
again if necessary.
6. Wrap-Up:
a. Once the conversation is over, hang up the phone (close the connection).
PROGRAM:
Server.java
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;
public class UDPServer
{
public static void main(String[] args) throws IOException
{
DatagramSocket ds = new DatagramSocket(1234);
byte[] receive = new byte[65535];
DatagramPacket DpReceive = null;
while (true)
{
DpReceive = new DatagramPacket(receive, receive.length);
ds.receive(DpReceive);
System.out.println("Client:-" + data(receive));
if (data(receive).toString().equals("bye"))
717822I153 – SENBAGAVALLI N
DEPARTMENT OF ARTIFICIAL INTELLIGENCE AND DATA 21ID15-DATA COMMUNICATION AND COMPUTER NETWORKS
SCIENCE
{
System.out.println("Client sent bye..... EXITING");
break;
}
receive = new byte[65535];
}
}
public static StringBuilder data(byte[] a)
{
if (a == null)
return null;
StringBuilder ret = new StringBuilder();
int i = 0;
while (a[i] != 0)
{
ret.append((char) a[i]);
i++;
}
return ret;
}
}
OUTPUT:
Client.java
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.util.Scanner;
OUTPUT:
PREPARATION 30
LAB PERFOMANCE 30
REPORT 40
TOTAL 100
RESULT:
Thus, the implementation of transmission control protocol and user datagram protocol using Java is done
successfully.
717822I153 – SENBAGAVALLI N
DEPARTMENT OF ARTIFICIAL INTELLIGENCE AND DATA 21ID15-DATA COMMUNICATION AND COMPUTER NETWORKS
SCIENCE
EX. NO: 8
AIM:
To implement file transfer protocol using java.
ALGORITHM:
1. Establish Connection:
a. The client initiates a TCP connection to the server on port 21 (FTP control port).
b. The server responds with a welcome message indicating readiness.
2. Authentication:
a. The client sends authentication credentials (username and password) to the server.
b. The server verifies the credentials. If valid, the server allows access; otherwise, it denies access.
3. Change Working Directory (optional):
a. The client can request to change the working directory on the server using commands like CWD.
4. Specify Transfer Mode (optional):
a. The client can specify the transfer mode (ASCII or binary) using commands like TYPE.
5. Data Transfer:
a. For file uploads, the client initiates a data connection (usually on port 20) to the server.
b. The client sends the file data over the data connection.
c. For file downloads, the server initiates a data connection to the client, and the server sends the file
data over the data connection.
6. Transfer Completion:
a. After the file transfer is complete, the server and client close the data connection.
7. Close Connection:
a. Once all transfers are complete, either the client or the server sends the QUIT command to terminate
the FTP session.
b. The server responds with a farewell message and closes the connection.
PROGRAM:
Server.java
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;
System.out.println("Server started");
System.out.println("Waiting for a client ...");
717822I153 – SENBAGAVALLI N
DEPARTMENT OF ARTIFICIAL INTELLIGENCE AND DATA 21ID15-DATA COMMUNICATION AND COMPUTER NETWORKS
SCIENCE
Socket socket = server.accept();
String lines=readInput.readUTF();
server.close();
socket.close();
writeOutput.close();
readInput.close();
ip.close();
}
}
OUTPUT:
Client.java
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileReader;
import java.net.Socket;
import java.util.Scanner;
System.out.println("Attempting to connect...");
System.out.println("Start transfering");
String transfer="";
BufferedReader reader;
try {
reader = new BufferedReader(new FileReader("D:\\GOD.txt"));
String line = reader.readLine();
while (line != null) {
transfer=transfer+line+"\n";
line = reader.readLine();
}
reader.close();
} catch (Exception e) {
e.printStackTrace();
}
writeOutput.writeUTF(transfer);
socket.close();
readInput.close();
writeOutput.close();
ip.close();
}
}
OUTPUT:
717822I153 – SENBAGAVALLI N
DEPARTMENT OF ARTIFICIAL INTELLIGENCE AND DATA 21ID15-DATA COMMUNICATION AND COMPUTER NETWORKS
SCIENCE
PREPARATION 30
LAB PERFOMANCE 30
REPORT 40
TOTAL 100
RESULT:
Thus, the implementation of file transfer protocol using Java is done successfully.
717822I153 – SENBAGAVALLI N
DEPARTMENT OF ARTIFICIAL INTELLIGENCE AND DATA 21ID15-DATA COMMUNICATION AND COMPUTER NETWORKS
SCIENCE
EX. NO: 9
AIM:
To implement data encryption and decryption using Java.
ALGORITHM:
Encryption Algorithm:
1. Key Generation: Generate a secret encryption key.
2. Encryption: Use the encryption key to encrypt the plaintext message.
3. Output: Output the encrypted ciphertext.
Decryption Algorithm:
1. Key Retrieval: Obtain the decryption key (the same key used for encryption).
2. Decryption: Use the decryption key to decrypt the ciphertext message.
3. Output: Output the decrypted plaintext.
PROGRAM:
Encrypter.java
// Import Java libraries
import java.util.Scanner;
717822I153 – SENBAGAVALLI N
DEPARTMENT OF ARTIFICIAL INTELLIGENCE AND DATA 21ID15-DATA COMMUNICATION AND COMPUTER NETWORKS
SCIENCE
OUTPUT:
PREPARATION 30
LAB PERFOMANCE 30
REPORT 40
TOTAL 100
RESULT:
Thus, the implementation of data encryption and decryption using Java is done successfully.
717822I153 – SENBAGAVALLI N