0% found this document useful (0 votes)
15 views14 pages

AJP Report Final

Uploaded by

theprounofficial
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views14 pages

AJP Report Final

Uploaded by

theprounofficial
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION MUMBAI

A
REPORT ON
“ Develop a file read in networking using udp”

UNDER THE GUIDANCE OF


MR. P. K. Shinde

DEPARTMENT OF COMPUTER ENGINEERING


DR. D. Y. PATIL POLYTECHNIC,
KASABA BAWADA, KOLHAPUR
SEMESTER - V
YEAR :- 2023-24
SUBMITTED BY:-

1) SAHIL BHOITE Roll No 3156


2) SAHIL SHIPURAKAR Roll No 3157
3) PRATIK GHARGE Roll No 3158
4) ADITYA PAWAR Roll No 3159
Certificate

This is to certify that ……………….….G-15………….…………….

From Dr. D. Y. Patil Polytechnic. Having Enrollment no-

2105390139, 2105390129 , 2105390150 , 2105390117

Has successfully completed ‘Project Report ’ Having title “ Develop

file read in networking using UDP ” in a Group

consisting of

…4… Persons under the Guidance of the MR. P. K. Shinde.

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.

I am thankful to Co-workers of this Micro-Project for their valuable


contribution. We are thankful to all those peoples who directly or
indirectly helped us in completion of this Micro Project.

Thank you All.

Date:
Place: Kolhapur
Index

Sr. No. Content Page No.

1 Rationale 1

2 Aims/Benefits of the Micro-Project 1

3 Course Outcome Achieved 1

4 Literature Review 1

5 Actual Methodology Followed 2-4

6 Actual Resources Used 4

7 Outputs of the Micro-Project 5-8

8 Skill Developed / Learning outcome of this 9


Micro-Project

9 Application of this Micro-Project 9


Develop file read in networking using UDP

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.

2.0 Aims/Benefits of the Micro-Project:


Aim: Develop file read in networking using UDP

Benefit:

a. Able to develop File read in networking using UDP.

b. Understand DatagramSocket , DatagramPacket.

c. Understand FileInputStream and FileOutputStream classes.

3.0 Course Outcomes Addressed:

1. Develop java programs using networking concepts.

4.0 Literature Survey –

Sr. No. Title of Website Link


1. JavaPoint https://www.javatpoint.com/

2. Bard https://bard.google.com/chat

1|Page
Develop file read in networking using UDP

5.0Actual Methodology Followed:

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:

DatagramSocket socket = new DatagramSocket(12345);

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.

byte[] sendData = "Hello, UDP!".getBytes();


InetAddress destinationAddress = InetAddress.getByName("example.com");
int port = 12345;
DatagramPacket packet = new DatagramPacket(sendData,sendData.length,
destinationAddress, port);
socket.send(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.

For example, to create an outgoing packet:


byte[] sendData = "Hello, DatagramPacket!".getBytes();
InetAddress destinationAddress = InetAddress.getByName("example.com");
int port = 12345;
DatagramPacket packet = new DatagramPacket(sendData, sendData.length,
destinationAddress, port);

3. Getting Data from DatagramPacket:


To extract data from a `DatagramPacket`, you can use its `getData()` method to obtain the
data as a array and `getLength()` to determine the length of the actual data in the packet.
byte[] receivedData = packet.getData();
int dataLength = packet.getLength();
String receivedMessage = new String(receivedData, 0, dataLength);

4. Handling Incoming Packets:


When receiving data, you create an empty `DatagramPacket` that will be filled with the
received data when `DatagramSocket` receives a packet.

byte[] receiveData = new byte[1024];


DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
socket.receive(receivePacket);

5. Address and Port Information:


The `DatagramPacket` also provides methods to get information about the source or
destination address and port. For example, `getAddress()` and `getPort()` can be used to obtain
the sender's address and port when receiving data.

InetAddress senderAddress = receivePacket.getAddress();


int senderPort = receivePacket.getPort();

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:

`FileOutputStream` is a Java class used for writing binary data to a file.


Like `FileInputStream`, it is part of the `java.io` package and is a subclass of
`OutputStream`.
To use `FileOutputStream`, you create an instance and specify the name or path of the file
you want to write to in its constructor. This establishes a connection to the file, allowing
you to write data to it.`FileOutputStream` provides methods for writing data to the file,
including the `write()` method to write a single byte and the `write(byte[] data)` method to
write a byte array.
Just as with `FileInputStream`, it is essential to handle exceptions during file operations,
and you should close the stream when you are finished writing data to release system
resources.

6.0 Actual Resources Used:

Sr. No. Name of Resource/material Specifications

1. Computer System DELL optiplex,2.93 GHz, 2 GB< RAM,


500 GB HDD
2. Operating System Windows 10

3. Software JDK 17.0.2

4. Links https://www.javatpoint.com/
https://bard.google.com/chat

4|Page
Develop file read in networking using UDP

7.0 Outputs of the Micro-Project:

Program Code for client side:

import java.io.*;
import java.net.*;

public class sender {


public static void main(String[] args) {
String filePath = "se.txt"; // Replace with the path to your file
String host = "localhost"; // Replace with the recipient's IP address or
hostname
int port = 006; // Replace with the recipient's port

try {
FileInputStream fileInputStream = new FileInputStream(filePath);
DatagramSocket socket = new DatagramSocket();

byte[] buffer = new byte[1024];


int bytesRead;

while ((bytesRead = fileInputStream.read(buffer)) != -1) {


DatagramPacket packet = new DatagramPacket(buffer,
bytesRead, InetAddress.getByName(host), port);
socket.send(packet);

fileInputStream.close();
socket.close();
System.out.println("File sent successfully.");

} catch (IOException e) {
e.printStackTrace();
}
}
}

5|Page
Develop file read in networking using UDP

Program Code for server side:

import java.io.*;
import java.net.*;

public class receiver {


public static void main(String[] args) {
int port = 004; // Replace with the port you want to listen on

try {
DatagramSocket socket = new DatagramSocket(port);

byte[] buffer = new byte[1024];


String pac;

DatagramPacket packet = new DatagramPacket(buffer,


buffer.length);

FileOutputStream fileOutputStream = new


FileOutputStream("ret.txt");

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:

Content in ret file after operation:

8|Page
Develop file read in networking using UDP

8.0 Skill Developed / Learning outcome of this Micro-Project

a) Understand the concept Of UDP.


b) Understand the concept and class like FileInputStream and
FileOutputStream.

9.0 Application of this Micro-Project

1.File sharing between server and client.


2. File read in UDP

9|Page
Develop file read in networking using UDP

10 | P a g
e

You might also like