Posts

Showing posts from April, 2022

GROUP

Image
 Multicast : UDPMulticastServer: import java.io.IOException; import java.net.DatagramPacket; import java.net.DatagramSocket; import java.net.InetAddress; public class UDPMulticastServer {    public static void sendUDPMessage(String message,    String ipAddress, int port) throws IOException {       DatagramSocket socket = new DatagramSocket();       InetAddress group = InetAddress.getByName(ipAddress);       byte[] msg = message.getBytes();       DatagramPacket packet = new DatagramPacket(msg, msg.length,group, port);       socket.send(packet);       socket.close();    }    public static void main(String[] args) throws IOException {       sendUDPMessage("This is a multicast messge", "230.0.0.0",4321);       sendUDPMessage("This is the second multicast messge","230.0.0.0", 4321);       sendUDPMessage("This is th...

MULTITHREADING

Image
Mainserver.java: /*  * To change this license header, choose License Headers in Project Properties.  * To change this template file, choose Tools | Templates  * and open the template in the editor.  */ /**  *  * @author staffpc  */ /*  * To change this license header, choose License Headers in Project Properties.  * To change this template file, choose Tools | Templates  * and open the template in the editor.  */ /**  *  * @author rttd  */ import java.io.*; import java.net.*; public class MainServer {    public static void main(String[] args) throws Exception    {        Socket s=null;        ServerSocket ss2=null;        System.out.println("Server Listening ......");        ss2=new ServerSocket(4446);        while(true)        {            try  ...

IPC

Image
 /*  * To change this license header, choose License Headers in Project Properties.  * To change this template file, choose Tools | Templates  * and open the template in the editor.  */ /**  *  * @author labpc  */ class Customer{     int amount=10000;          synchronized void withdraw(int amount){     System.out.println("going to withdraw...");          if(this.amount<amount){     System.out.println("Less balance; waiting for deposit...");     try{wait();}catch(Exception e){}     }     this.amount-=amount;     System.out.println("withdraw completed...");     }          synchronized void deposit(int amount){     System.out.println("going to deposit...");     this.amount+=amount;     System.out...

RPC/RMI

NAME RESOLUTION PROTOCOL

Image
Code:   import java.io.*; import java.net.*; class NameResolution {     public static void main(String[] args)     {         try {             // IP Address             InetAddress addr                 = InetAddress.getByName("23.229.203.68");                // Host name             System.out.println("Host name is: "                                + addr.getHostName());                // Host Address             System.out.println("Ip address is: "                                + addr.getHostAddress());         }     ...

CLOCK SYNCHRONIZATION (Lamport's Algorithm)

Image
Lamport.java: import java.util.*; import java.util.Scanner; import javax.swing.*; import java.awt.*; import java.awt.geom.*; public class Lamport{ int e[][]=new int[10][10]; int en[][]=new int[10][10]; int ev[]=new int[10]; int i,p,j,k; HashMap<Integer,Integer> hm=new HashMap<Integer,Integer>(); int xpoints[] =new int[5]; int ypoints[] =new int[5]; class draw extends JFrame{ private final int ARR_SIZE = 4;             void drawArrow(Graphics g1, int x1, int y1, int x2, int y2) {                 Graphics2D g = (Graphics2D) g1.create();                 double dx = x2 - x1, dy = y2 - y1;                 double angle = Math.atan2(dy, dx);                 int len = (int) Math.sqrt(dx*dx + dy*dy);                 AffineTransform at = AffineTransform.getTr...

LOAD BALANCING

Image
 IpPool.java: import java.util.Map; import java.util.concurrent.ConcurrentHashMap; public class IpPool {     public static Map<String, Integer> ipMap = new ConcurrentHashMap<>();     static {         ipMap.put("192.168.1.1", 10);         ipMap.put("192.168.1.2", 10);         ipMap.put("192.168.1.3", 10);         ipMap.put("192.168.1.4", 10);         ipMap.put("192.168.1.5", 10);         ipMap.put("192.168.1.6", 10);         ipMap.put("192.168.1.7", 10);         ipMap.put("192.168.1.8", 10);         ipMap.put("192.168.1.9", 10);         ipMap.put("192.168.1.10", 10);     } } LoadBalance.java:Interface public interface LoadBalance {     String getServer(String clientIp); } RoundRobin.java: import java.util.ArrayList; import java.util.Li...

ELECTION ALGO

Image
import java.io.*;   import java.util.Scanner;      // create class BullyAlgoExample to understand how bully algorithms works   public class BullyAlgoExample{              // declare variables and arrays for process and their status   static int numberOfProcess;   static int priorities[] = new int[100];   static int status[] = new int[100];   static int cord;          // main() method start   public static void main(String args[])throws IOException   // handle IOException       {       // get input from the user for the number of processes    System.out.println("Enter total number of processes:");              // create scanner class object to get input from user           Scanner sc = new Scanner(Syste...

DISTRIBUTED FILE SYSTEM

   Distributed File System In this article, you will learn about the distributed file system in the operating system and its features, components, advantages, and disadvantages. What is Distributed File System? A  distributed file system (DFS)  is a file system that is distributed on various file servers and locations. It permits programs to access and store isolated data in the same method as in the local files. It also permits the user to access files from any system. It allows network users to share information and files in a regulated and permitted manner. Although, the servers have complete control over the data and provide users access control. DFS's primary goal is to enable users of physically distributed systems to share resources and information through the  Common File System (CFS) . It is a file system that runs as a part of the  operating systems . Its configuration is a set of workstations and mainframes that a LAN connects. The process of cre...

DEADLOCK

Image
 DeadLockExample.java: package deadlock; public class DeadlockExample {     public static void main(String[] args) {       final String resource1 = "ratan jaiswal";       final String resource2 = "vimal jaiswal";       // t1 tries to lock resource1 then resource2       Thread t1 = new Thread() {        @Override()               public void run() {             synchronized (resource1) {              System.out.println("Thread 1: locked resource 1");                 try { Thread.sleep(100);} catch (Exception e) {}                 synchronized (resource2) {               System.out.println("Thread 1: locked resource 2");...

MUTUAL EXCLUSION

Image
Mutual Exclusion Token Based Algorithm:  EchoServer.java: import java.io.*; import java.net.*; public class EchoServer implements Runnable {     Socket socket=null;     static ServerSocket ss;     EchoServer(Socket newSocket)     {         this.socket=newSocket;            }     public static void main(String args[]) throws IOException     {         ss=new ServerSocket(7000);         System.out.println("Server Started");         while(true)         {             Socket s = ss.accept();             EchoServer es = new EchoServer(s);             Thread t = new Thread(es);             t.start();         }     }     public void run()   ...

CORBA

  To study CORBA Technology Theory:  (What is CORBA?, What is it used for?, Draw and explain Corba Architecture. Application: Name of the Paper.   (based of paper you referred) Discussion: (discuss the Key point in the paper) Conclusion: (write down your understanding of CORBA with reference to the paper you referred.)