Skip to main content

Posts

Showing posts from October, 2019

Write a program for congestion control using leaky bucket algorithm

import java.util.*; public class LBA {        public static void main(String[] args ) {              // TODO Auto-generated method stub              int op ;              Scanner s = new Scanner(System. in );              int bktcap =0;              int remain =0;              int pkt []= new int [10];              System. out .println( "Enter Bucket size" );              bktcap = s .nextInt();              System. out .println( "Enter value n" );              int n = s .nextInt();              System. out .println( "Enter datarate" );              int dr = s .nextInt();              System. out .println( "Enter input values" );              for ( int i =0; i < n ; i ++){              int val = s .nextInt();              pkt [ i ]= val ;              }              for ( int i =0; i <= n ; i ++){                     int total = pkt [ i ]+ remain ;                     if ( t

Write a program for simple RSA algorithm to encrypt and decrypt the data.

import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.InetAddress; import java.net.ServerSocket; import java.net.Socket; import java.util.*; public class RSA{        public static void main(String[] args) {              // TODO Auto-generated method stub              Scanner s=new Scanner(System.in);              RSA r=new RSA();              System.out.println("Enter value for p");              int p=s.nextInt();              System.out.println("Enter value for q");              int q=s.nextInt();              int n=(p*q);              int fai=((p-1)*(q=1));               System.out.println("Enter value for e");              int e=s.nextInt();                           while(true) {                     if(GCD(fai,e)!=1) {                            System.out.println("Enter value for e"

Write a program on datagram socket for client/server to display the messages on client side, typed at the server side.

Sender import java.util.*; import java.net.*; public class Sender {   public static void main(String args []) throws Exception { System. out .println( "sender " ); DatagramSocket ds = new DatagramSocket(); Scanner s = new Scanner(System. in ); System. out .println( "enter the message" ); while ( true ) { String msg = s .nextLine(); InetAddress ip =InetAddress. getByName ( "127.0.0.1" ); DatagramPacket dp = new DatagramPacket( msg .getBytes(), msg .length(), ip ,3000); ds .send( dp ); } } } Receiver import java.util .*; import java.io.IOException ; import java.net.*; public class Receiver {   public static void main(String args []) throws Exception { byte [] buf = new byte [1024]; System. out .println( "receiver " ); DatagramSocket ds = new DatagramSocket(3000); while ( true ) { DatagramPacket dp = new DatagramPacket( buf ,1024); ds .receive( dp );

Using TCP/IP sockets, write a client – server program to make the client send the file name and to make the server send back the contents of the requested file if present.

Client import java.io.*; import java.net.*; import java.util.*; public class Client { public static void main(String args[]) { Socket socket=null; try { socket=new Socket(InetAddress.getLocalHost().getHostName(),9912); BufferedReader reader=new BufferedReader(new InputStreamReader(socket.getInputStream())); PrintWriter writer=new PrintWriter(socket.getOutputStream(),true); System.out.println("Enter the file name"); Scanner s=new Scanner(System.in); String file=s.nextLine(); writer.println(file); System.out.println("Reading Client......"); String h=null; while((h=reader.readLine()) !=null) System.out.println(h); } catch(IOException e) { e.printStackTrace(); } finally { try { socket.close(); } catch(IOException e) { e.printStackTrace(); } } } } Server import java.io.*; import java.net.*; public class Server { public static class Cl