AJP Report Final
AJP Report Final
A
REPORT ON
“ Develop a file read in networking using udp”
consisting of
Signature Signature
Head of the Department Seal Head of the Institute
ACKNOWLEDGMENT
It’s our Pleasure to express sincere and heartiest thanks to our Micro-
Project guide Prof. P. K. Shinde for their valuable guidance,
encouragement and support for the accomplishment of Micro-Project.
We are also really thankful to our Principal Dr. M. M. Narke and the
Head of Department Prof. P. K. Shinde. for their constant
encouragement and motivation for the accomplishment of the Micro-
Project by expressing their guidelines regarding importance of Micro-
Project in developing our career.
Date:
Place: Kolhapur
Index
1 Rationale 1
4 Literature Review 1
1.0 Rationale:
In the project of “File transfer in networking in UDP” user can able to send the file
from client to server and server to client. In this project developers used
DatagramPacket and DatagramSocket classes.When user runs the server program
the file is sent to server side and server creates new file and receives data from file
client side.The client and server must have same port number for UDP services.
Benefit:
2. Bard https://bard.google.com/chat
1|Page
Develop file read in networking using UDP
1. Gathered Information:
1.DatagramSocket
The `DatagramSocket` class in Java is part of the `java.net` package and is used for network
communication using User Datagram Protocol (UDP). It provides a way to send and receive
datagrams over a network, making it suitable for connectionless, lightweight, and low-latency
communication. Here's some key information about the `DatagramSocket` class:
1. Connectionless Communication:
Unlike TCP (Transmission Control Protocol), which provides connection-oriented
communication, UDP (User Datagram Protocol) is connectionless. `DatagramSocket` is used
for sending and receiving individual datagrams (small packets) without establishing a
continuous connection.
2. Creating DatagramSocket:
You can create a `DatagramSocket` instance by specifying the local port on which it will
operate. For example:
3. Sending Data:
To send data, you create a `DatagramPacket` containing the data and the destination
address, and then use the `send()` method of the `DatagramSocket` to send the packet.
4. Receiving Data:
To receive data, you use the `receive()` method of the `DatagramSocket`, which blocks
until a datagram is received. Received data is encapsulated in a `DatagramPacket`
2|Page
Develop file read in networking using UDP
2.DatagramPacket:
1. DatagramPacket:
The `DatagramPacket` class in Java, also part of the `java.net` package, is used to encapsulate
data to be sent or received via a `DatagramSocket`. It represents a single packet of data in a
network communication using the User Datagram Protocol (UDP).
2. Creating DatagramPacket:
You can create a `DatagramPacket` by providing two main pieces of information:
- The data to be sent or the buffer to receive data.
- The destination address and port for outgoing packets or an empty buffer for incoming
packets.
3|Page
Develop file read in networking using UDP
4.FileInputStream:
`FileInputStream` is a Java class that is used for reading binary data from a file.
It is part of the `java.io` package and is a subclass of `InputStream`.
To use `FileInputStream`, you create an instance by providing the name or path of the file
you want to read as a parameter to its constructor. This establishes a connection to the file,
allowing you to read data from it.`FileInputStream` provides methods to read data from the
file, such as the `read()` method to read a single byte at a time and the `read(byte[] data)`
method to read multiple bytes at once.
Exception handling is essential when working with `FileInputStream` to handle potential
errors during file operations. Properly closing the stream after use is crucial to release
system resources.
5.FileOutputStream:
4. Links https://www.javatpoint.com/
https://bard.google.com/chat
4|Page
Develop file read in networking using UDP
import java.io.*;
import java.net.*;
try {
FileInputStream fileInputStream = new FileInputStream(filePath);
DatagramSocket socket = new DatagramSocket();
fileInputStream.close();
socket.close();
System.out.println("File sent successfully.");
} catch (IOException e) {
e.printStackTrace();
}
}
}
5|Page
Develop file read in networking using UDP
import java.io.*;
import java.net.*;
try {
DatagramSocket socket = new DatagramSocket(port);
while (true) {
socket.receive(packet);
pac=new String(packet.getData(),0, packet.getLength());
System.out.println(pac);
pac.getBytes();
fileOutputStream.write(buffer);
fileOutputStream.flush();
fileOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("recived successfully");
}
}
6|Page
Develop file read in networking using UDP
Output : -
Content in se file:
Sever program:
7|Page
Develop file read in networking using UDP
Client program:
8|Page
Develop file read in networking using UDP
9|Page
Develop file read in networking using UDP
10 | P a g
e