Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

UDP Server Code and Client-Server Model for File Transfer, Assignments of Network security

Two different codes for a DCCN lab assessment. The first code is a UDP based server code that calculates the age of a client based on their date of birth. The second code is a client-server model for file transfer, which includes HTTPS for uploading files to an FTP server, encryption and decryption of file data with security algorithms, and code for generating a key for encryption and decryption using TCP/IP client server sockets. sample code and output for both scenarios.

Typology: Assignments

2021/2022

Available from 03/27/2023

utkarsh-goyal-1
utkarsh-goyal-1 🇺🇸

8 documents

1 / 12

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
DCCN LAB
ASSESSMENT-5
Name: Utkarsh Goyal
Reg.No 19BIT0402
COMPUTER NETWORKS LAB ASSIGNMENT
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download UDP Server Code and Client-Server Model for File Transfer and more Assignments Network security in PDF only on Docsity!

DCCN LAB

ASSESSMENT- 5

Name: Utkarsh Goyal

Reg.No 19BIT

1. Write a UDP based server code to get the date of birth

of the client and calculate the age as on today. The client

has to enter the year, month and day of birth. For

example, if the date of birth of a user is 1/07/2001 then

his age is 14 years 0 months and 17 days if today's date is

18/07/2018. Get today's date from the server.

Code for Date formatting

Creating UDP sockets for server and client

Code for validation of date format and computation of

age for UDP transfer of segments.

Ans. CODE : import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class AgeCalculator { private static Age calculateAge(Date birthDate)

//if month difference is in negative then reduce years by one //and calculate the number of months. if (months < 0) { years--; months = 12 - birthMonth + currMonth; if (now.get(Calendar.DATE) < birthDay.get(Calendar.DATE)) months--; } else if (months == 0 && now.get(Calendar.DATE) < birthDay.get(Calendar.DATE)) { years--; months = 11; } //Calculate the days if (now.get(Calendar.DATE) > birthDay.get(Calendar.DATE)) days = now.get(Calendar.DATE) - birthDay.get(Calendar.DATE); else if (now.get(Calendar.DATE) < birthDay.get(Calendar.DATE)) {

int today = now.get(Calendar.DAY_OF_MONTH); now.add(Calendar.MONTH, - 1); days = now.getActualMaximum(Calendar.DAY_OF_MONTH)

  • birthDay.get(Calendar.DAY_OF_MONTH) + today; } else { days = 0; if (months == 12) { years++; months = 0; } } //Create new Age object return new Age(days, months, years); } public static void main(String[] args) throws ParseException { SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); Date birthDate = sdf.parse("29/11/1981");

2. A reputed organization has two branches in Vellore. In one of

the branch office, a new manager has been appointed. The

Senior Manager from the main office has to send the important

records to the branch office. Implement a client-server model

to accomplish this.

Understating of HTTPS for uploading of files to FTP server.

Encryption and decryption of the file's data with security

algorithms.

Code for generation of a key for encryption and decryption

using TCP/IP client server sockets.

Ans.

Code:

Server-side program: import java.io.; import java.net.; class ManagerServer { public static void main(String args[]) throws Exception { ServerSocket ss = new ServerSocket(1080); Socket s = ss.accept(); InetAddress IA = InetAddress.getByName("localhost");

File file = new File("Clienttext.java"); FileInputStream fis = new FileInputStream(file); BufferedInputStream bis = new BufferedInputStream(fis); OutputStream o = s.getOutputStream(); byte[] contents; long fileLength = file.length(); long current = 0; long start = System.nanoTime(); while(current!=fileLength) { int size = 10000; if(fileLength-current>=size) { current+=size; } else { size =(int)(fileLength-current); current = fileLength; } contents = new byte[size]; bis.read(contents,0,size); o.write(contents);

while((bytesread = is.read(contents))!=-1) { bos.write(contents,0,bytesread); } bos.flush(); s.close(); System.out.println("File saved successfully"); } } Output: