CodeSaved

Programs

import java.io.*;
            import java.net.*;
            
            public class RemoteCommandServer1 {
                public static void main(String[] args) throws IOException {
                    final int PORT = 12345;
                    ServerSocket serverSocket = new ServerSocket(PORT);
                    System.out.println("Server started. Listening on port " + PORT);
                    System.out.println("Server is waiting for client");
            
                    while (true) {
                        Socket clientSocket = serverSocket.accept();
                        System.out.println("Client connected: " + clientSocket.getInetAddress().getHostName());
                        new Thread(new CommandHandler(clientSocket)).start();
                    }
                }
            
                static class CommandHandler implements Runnable {
                    private final Socket clientSocket;
            
                    CommandHandler(Socket socket) {
                        this.clientSocket = socket;
                    }
            
                    public void run() {
                        try (BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
                             PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true)) {
                             
                            String command = in.readLine();
                            System.out.println("Received command: " + command);
                            try {
                                ProcessBuilder processBuilder = new ProcessBuilder(command.split(" "));
                                processBuilder.redirectErrorStream(true); // Redirect error stream to output stream
                                Process process = processBuilder.start();
                                
                                try (BufferedReader processOutput = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
                                    String line;
                                    while ((line = processOutput.readLine()) != null) {
                                        out.println(line);
                                    }
                                }
                            } catch (IOException e) {
                                out.println("Error executing command: " + e.getMessage());
                            }
                        } catch (IOException e) {
                            e.printStackTrace();
                        } finally {
                            try {
                                clientSocket.close();
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                        }
                    }
                }
            } 




import java.io.*; import java.net.*; public class RemoteCommandClient1 { public static void main(String[] args) throws IOException { final String SERVER_IP = "localhost"; final int PORT = 12345; try (Socket socket = new Socket(SERVER_IP, PORT); PrintWriter out = new PrintWriter(socket.getOutputStream(), true); BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()))) { System.out.println("Connected to server."); out.println("hostname is pratyusha"); String line; while ((line = in.readLine()) != null) { System.out.println("Server response: " + line); } } catch (IOException e) { e.printStackTrace(); } } }

import java.io.*;
import java.net.*;
public class WebPages {
public static void main(String[] args) throws Exception {
URL u = new URL("https://www.mlrit.ac.in");
BufferedReader r=new BufferedReader(new InputStreamReader(u.openStream()));
FileWriter w=new FileWriter("downloaded_page.html");
String line;
while((line=r.readLine())!=null)
w.write(line + "\n");
r.close();
w.close();
System.out.println("Webpage downloaded successfully!");
}
}
          

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class FileServer {
    public static void main(String[] args) {
        final int PORT = 12345;
        final String fileName = "amaan.txt";

        try (ServerSocket serverSocket = new ServerSocket(PORT)) {
            System.out.println("Server started. Waiting for a client...");

            try (Socket clientSocket = serverSocket.accept()) {
                System.out.println("Client connected: " + clientSocket.getInetAddress().getHostName());
                PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
                out.println(fileName);

                FileInputStream fis = new FileInputStream(fileName);
                BufferedOutputStream bos = new BufferedOutputStream(clientSocket.getOutputStream());

                byte[] buffer = new byte[8192];
                int bytesRead;
                while ((bytesRead = fis.read(buffer)) != -1) {
                    bos.write(buffer, 0, bytesRead);
                }

                bos.flush();
                fis.close();
                System.out.println("File sent: " + fileName);
            }
        } catch (IOException e) {
            System.err.println("Error: " + e.getMessage());
        }
    }
}





import java.io.*; import java.net.Socket; public class FileClient { public static void main(String[] args) { final String SERVER_IP = "localhost"; final int PORT = 12345; String fileName = "amaan.txt"; try (Socket socket = new Socket(SERVER_IP, PORT)) { System.out.println("Connected to server."); BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream())); String receivedFileName = in.readLine(); System.out.println("Requested file: " + receivedFileName); InputStream is = socket.getInputStream(); FileOutputStream fos = new FileOutputStream("received_" + receivedFileName); BufferedOutputStream bos = new BufferedOutputStream(fos); byte[] buffer = new byte[8192]; int bytesRead; while ((bytesRead = is.read(buffer)) != -1) { bos.write(buffer, 0, bytesRead); } bos.flush(); bos.close(); fos.close(); System.out.println("File received: received_" + receivedFileName); } catch (IOException e) { System.err.println("Error: " + e.getMessage()); } } }

            
import java.io.*; import java.net.*; public class EchoServer { public static void main(String[] args) { final int portNumber = 5555; System.out.println("Echo server started on port " + portNumber); try ( ServerSocket serverSocket = new ServerSocket(portNumber); Socket clientSocket = serverSocket.accept(); PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true); BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); ) { System.out.println("Client connected"); String inputLine; while ((inputLine = in.readLine()) != null) { System.out.println("Received from client: " + inputLine); out.println(inputLine); // Echo back to client } } catch (IOException e) { System.out.println("Exception caught when trying to listen on port " + portNumber + " or listening for a connection"); System.out.println(e.getMessage()); }}}




import java.io.*; import java.net.*; public class EchoClient { public static void main(String[] args) { final String host = "localhost"; final int portNumber = 5555; try ( Socket echoSocket = new Socket(host, portNumber); PrintWriter out = new PrintWriter(echoSocket.getOutputStream(), true); BufferedReader in = new BufferedReader(new InputStreamReader(echoSocket.getInputStream())); BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in)) ) { String userInput; System.out.println("Enter messages to send to the server (type 'exit' to quit):"); while ((userInput = stdIn.readLine()) != null) { if ("exit".equalsIgnoreCase(userInput)) { System.out.println("Exiting..."); break; } out.println(userInput); System.out.println("Server echoed: " + in.readLine()); } } catch (IOException e) { System.err.println("IOException caught: " + e.getMessage()); } } }

import java.io.*; import java.net.*; public class UDPServer { public static void main(String[] args) { final int PORT = 9876; try (DatagramSocket serverSocket = new DatagramSocket(PORT)) { byte[] receiveData = new byte[1024]; System.out.println("Server started. Listening on port " + PORT); while (true) { DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length); serverSocket.receive(receivePacket); String message = new String(receivePacket.getData(), 0, receivePacket.getLength()); System.out.println("Client: " + message); InetAddress clientAddress = receivePacket.getAddress(); int clientPort = receivePacket.getPort(); String responseMessage = "Message received successfully!"; byte[] sendData = responseMessage.getBytes(); DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, clientAddress, clientPort); serverSocket.send(sendPacket); } } catch (IOException e) { e.printStackTrace(); } } }




import java.io.*; import java.net.*; public class UDPClient { public static void main(String[] args) { final String SERVER_IP = "localhost"; final int SERVER_PORT = 9876; try (DatagramSocket clientSocket = new DatagramSocket(); BufferedReader userInput = new BufferedReader(new InputStreamReader(System.in))) { InetAddress serverAddress = InetAddress.getByName(SERVER_IP); while (true) { System.out.print("Enter message to send to server: "); String message = userInput.readLine(); byte[] sendData = message.getBytes(); DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, serverAddress, SERVER_PORT); clientSocket.send(sendPacket); byte[] receiveData = new byte[1024]; DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length); clientSocket.receive(receivePacket); String responseMessage = new String(receivePacket.getData(), 0, receivePacket.getLength()); System.out.println("Server: " + responseMessage); } } catch (IOException e) { e.printStackTrace(); } } }

import java.io.*; import java.net.*; public class Chatclient{ private static final String SERVER_IP="127.0.0.1"; private static final int SERVER_PORT=9000; public static void main(String args[]) throws Exception { Socket socket=new Socket(SERVER_IP, SERVER_PORT); System.out.println("Connected to the chat server.."); BufferedReader reader=new BufferedReader(new InputStreamReader (socket.getInputStream())); PrintWriter writer =new PrintWriter(socket.getOutputStream(), true); Thread input=new Thread(()->{ BufferedReader userInput=new BufferedReader(new InputStreamReader(System.in)); try{ while(true) { String line=userInput.readLine(); writer.println(line);} } catch(IOException e) { System.out.println(e);} }); input.start(); String serverMessage; try{ while((serverMessage=reader.readLine())!=null) { System.out.println("Server: "+serverMessage); } }catch(IOException e){ e.printStackTrace(); } finally{ socket.close(); }}}




import java.io.*; import java.net.*; import java.util.*; public class Chatserver{ private static final int PORT=9000; private static Set writers=new HashSet<>(); public static void main(String args[]) throws Exception{ System.out.println("The chat server is running...."); ServerSocket listener=new ServerSocket (PORT); try{ while(true) { new Handler(listener.accept()).start(); }} finally{ listener.close(); }} private static class Handler extends Thread { private Socket socket; private PrintWriter out; private BufferedReader in; public Handler (Socket socket) { this.socket=socket; } public void run(){ try{ in=new BufferedReader(new InputStreamReader(System.in)); out=new PrintWriter (socket.getOutputStream(), true); synchronized (writers) { writers.add(out); } while(true) { String message=in.readLine(); if(message==null){ return; } System.out.println("Recieved message: "+message); synchronized(writers) { for(PrintWriter writer: writers) { writer.println(message); }}}} catch(IOException e) { System.out.println(e); } finally { if(out!=null) { writers.remove(out); } try { socket.close(); } catch(IOException e) { System.out.println(e); }}}}}

Lab Internal 2

CN

            WEEK 2,7,9
            
            import java.io.*;
            import java.util.*;
            import java.net.Socket;
             class Client {
                public static void main(String[] args) throws IOException{
                    Socket s=new Socket("localhost",9999);
                    System.out.println("Connection established");
                    Scanner sc=new Scanner(System.in);
                    BufferedReader br=new BufferedReader(new InputStreamReader(s.getInputStream()));
                    PrintStream ps=new PrintStream(s.getOutputStream());
                    String msg;
                    do{
                        System.out.println("Enter Message");
                        msg=sc.nextLine();
                        ps.println(msg);
                        System.out.println("Server: "+br.readLine());
                    }while(!msg.equals("exit"));
            }
            }
            
            
            
            import java.io.*;
            import java.net.*;
            import java.net.Socket;
            
            class Server{
                public static void main(String[] args)throws IOException{ {
                    ServerSocket ss=new ServerSocket(9999);
                    System.out.println("Server is running on port 9999");
                    Socket s=ss.accept();
                    System.out.println("Connection established");
                    BufferedReader br=new BufferedReader(new InputStreamReader(s.getInputStream()));
                    PrintStream ps=new PrintStream(s.getOutputStream());
                    String msg;
                    do{
                        msg=br.readLine();
                        System.out.println("Client: "+msg);
                        ps.println("Message received Successfully");
                    }while(!msg.equals("exit"));
                    ss.close();
                    s.close();
                    }
                }
            }
            
            
            
WEEK 3
            
            import java.net.*;
            import java.io.*;
            public class ftpserver {
                public static void main(String[] args)throws Exception{
                    ServerSocket s = new ServerSocket(2999);
                    System.out.println("Server is running on port 2999");
                    Socket ss= new Socket();
                    ss=s.accept();       
                    System.out.println("Server is connected on port 2999");
                    BufferedReader br=new BufferedReader(new FileReader("file.txt"));
                    PrintStream ps= new PrintStream(ss.getOutputStream());
                    String str;
                    while((str=br.readLine())!=null){
                        ps.println(str);
                    }
            }
            }
            
            
            
            import java.io.*;
            import java.net.*;
            
            
            public class ftpclient {
                public static void main(String[] args) throws Exception{
                Socket s=new Socket("localhost",2999);
                BufferedReader br=new BufferedReader(new InputStreamReader(s.getInputStream()));
                PrintWriter pw=new PrintWriter(new FileWriter("receivedfile.txt"));
                String line;
                while((line=br.readLine())!=null){
                    pw.println(line);
                }
                }
            }
            
            
            WEEK 4
            
            import java.io.*;
            import java.net.*;
            public class remotecommandserver
            {
               public static void main(String []args) throws Exception
                {
                  ServerSocket ss=new ServerSocket(8899);
                  Socket stk=ss.accept();
                  BufferedReader br=new BufferedReader(new InputStreamReader(stk.getInputStream()));
                  PrintStream ps=new PrintStream(stk.getOutputStream());
                  String command=br.readLine();
                  System.out.println("command is :" + command);
                  ProcessBuilder pb=new ProcessBuilder(command);
                  Process pro=pb.start();
                  BufferedReader brp=new BufferedReader(new InputStreamReader(pro.getInputStream()));
                  String line;
                  while((line=brp.readLine())!=null)
                  {
                     ps.println(line);
                  }
                 System.out.println("command executed succesfully...");
                 ps.println("null");
               }}
                  
            
            
            
            import java.io.*;
            import java.util.*;
            import java.net.*;
            public class remotecommandclient
            {
               public static void main(String []args) throws Exception
                {
                  Scanner sc=new Scanner(System.in);
                  Socket s=new Socket("localhost",8899);
                  BufferedReader br=new BufferedReader(new InputStreamReader(s.getInputStream()));
                  PrintStream ps=new PrintStream(s.getOutputStream());
                  System.out.println("enter the command to execute...");
                 String command=sc.next();
                  ps.println(command);
                  String response=br.readLine();
                do{ 
                    System.out.println("executed and result is: "+response);
                    response=br.readLine();
                }
                while(!response.equals("null"));
                 } 
               }
            
            
            
            WEEK 5
            
            import java.net.*;
            public class datagramserver{
                public static void main(String[] args) throws Exception{
                  DatagramSocket s=new DatagramSocket(9999);
                  byte[] bytes=new byte[1024];
                  DatagramPacket ss=new DatagramPacket(bytes, bytes.length);
                  s.receive(ss);
                  String str=new String(ss.getData(),0,ss.getLength());
                  System.out.println("From Client: "+str);
                  ss=new DatagramPacket(str.getBytes(),str.length(),ss.getAddress(),ss.getPort());
                  s.send(ss);
                  s.close();
                }
            }
            
            
            import java.net.*;
            public class datagramclient {
                public static void main(String[] args) throws Exception{
                    DatagramSocket s=new DatagramSocket();
                    String str="Hello Server,from Amaan";
                    byte[] buffer=str.getBytes();
                    DatagramPacket ss=new DatagramPacket(buffer, buffer.length, InetAddress.getByName("localhost"), 9999);
                    s.send(ss);
                    buffer=new byte[1024];
                    ss= new DatagramPacket(buffer,buffer.length);
                    s.receive(ss);
                    System.out.println("From Server:"+new String(buffer,0,buffer.length));
                    s.close();
                    
                }
            }
            
            
            WEEK 6
            
            import java.io.*;
            import java.net.*;
            
            public class webpage {
                public static void main(String[] args) throws Exception{
                    URL u= new URL("https://www.google.com/");
                    BufferedReader br=new BufferedReader(new InputStreamReader(u.openStream()));
                    FileWriter fw=new FileWriter("webpage.html");
                    String line;
                    while((line=br.readLine())!=null){
                        fw.write(line);
                        fw.write("\n");
                    }
                    fw.close();
                    br.close();
                }
            }
            
            
            
            WEEK 8
            
            import java.rmi.*;
            import java.rmi.registry.LocateRegistry;
            public class rmiserver {
              public static void main(String[] args)throws Exception{ 
                AddC obj = new AddC();
                LocateRegistry.createRegistry(9090);
                Naming.rebind("rmi://localhost:9090/ADD", obj);
                System.out.println("Server started...");
              }
            }
            
            
            
            import java.rmi.*;
            public class rmiclient
            {
              public static void main(String []args) throws Exception
              {
              AddI obj=(AddI)Naming.lookup("rmi://localhost:9090/ADD");
              int n=obj.add(5,4);
               System.out.println("Addition is:" + n);
            }}
            
            
            
            import java.rmi.*;
            public interface AddI extends Remote{
                public int add(int a,int b) throws Exception;
               }
            
            
            import java.rmi.server.*;
            public class AddC extends UnicastRemoteObject implements AddI
            {
              public AddC() throws Exception{};
              public int add(int a,int b)
               {
                return a+b;
               }}
            
            
            WEEK 10
            
            import java.util.*;
            public class cookies {
                public static void main(String[] args) {
                    Map  cookies=new HashMap<>();
                    cookies.put("key1”,”AMAAN1”);
                    cookies.put("key2”,”AMAAN2”);
                    for(Map.Entry e :cookies.entrySet()){
                        System.out.println("Key: "+e.getKey()+" Value: "+e.getValue());
                    }
            
                }
            
            }
            
            
            WEEK 12
            
            import java.util.*;
            
            public class vector {
                public static void main(String[] args) {
                    int[][] dm = {{0, 1, 3, Integer.MAX_VALUE}, {1, 0, Integer.MAX_VALUE, 2}, {3, Integer.MAX_VALUE, 0, 2}, {Integer.MAX_VALUE, 2, 2, 0}};
                    int n = 4;
                    int[][] dvt = Arrays.copyOf(dm, n);
                    
                    for (int i = 0; i < n; i++) {
                        for (int j = 0; j < n; j++) {
                            if (j != i) {
                                for (int k = 0; k < n; k++) {
                                    if (k != i && dvt[j][k] > dm[j][i] + dvt[i][k]) {
                                        dvt[j][k] = dm[j][i] + dvt[i][k];
                                    }
                                }
                            }
                        }
                    }
            
                    for (int[] row : dvt) {
                        for (int cell : row) {
                            System.out.print((cell == Integer.MAX_VALUE) ? "INF " : cell + " ");
                        }
                        System.out.println();
                    }
                }
            }
            
            
            
            

Programs


          //server
          import java.util.*;
          import java.io.*;
          import java.net.*;
          public class server{
              public static void main(String []args) throws Exception
              {
                  System.out.println("Server has started...!!!");
                  ServerSocket ss =new ServerSocket(9999);
                  Socket stk=ss.accept();
                  System.out.println("server is connected...!!");
                  BufferedReader bf=new BufferedReader(new InputStreamReader(stk.getInputStream()));
                  PrintStream ps=new PrintStream(stk.getOutputStream());
                  String msg;
                  do{
                      msg=bf.readLine();
                      System.out.println("message received from client:"+ msg);
                      ps.println("message received succesfully!!");
                  }while(!msg.equals("end"));
              }
          } 
        
        
import java.io.*; import java.util.*; import java.net.*; public class client{ public static void main(String []args) throws Exception { Scanner sc=new Scanner(System.in); Socket stk=new Socket("localhost",9999); BufferedReader br=new BufferedReader(new InputStreamReader(stk.getInputStream())); PrintStream ps=new PrintStream(stk.getOutputStream()); String msg; do{ System.out.println("enter a message"); msg=sc.next(); ps.println(msg); System.out.println("message sent to server"+ msg); String response=br.readLine(); System.out.println("Server response:"+ response); }while(!msg.equals("end")); } }

//Helloserver
  

import java.rmi.*;
import java.rmi.registry.*;
public class HelloServer
{
  public static void main(String []args) 
  {  
     try{
       LocateRegistry.createRegistry(4444);
       Helloimpl obj=new Helloimpl();
       Naming.rebind("rmi://localhost:4444/Helloworld",obj);
      System.out.println("Server is ready");
      }
     catch(Exception e){
           System.out.println(e);
         }
}}



//client

import java.net.*;
import java.io.*;
import java.rmi.*;
public class HelloClient{
  public static void main(String []args)
{
  try
  {
    Helloworld remobj=(Helloworld)Naming.lookup("rmi://localhost:4444/Helloworld");
     System.out.println(remobj.display());
   }
  catch(Exception e){
     System.out.println(e);
    }
}}
   
//implements remote interface

import java.rmi.*;
import java.rmi.server.UnicastRemoteObject;
public class Helloimpl extends UnicastRemoteObject implements Helloworld
{
       public Helloimpl() throws RemoteException{}
       public String display() throws RemoteException
       {
         return "Hello World from server";
       }
}
//define remote interface

import java.rmi.*;
public interface Helloworld extends Remote
{
  String display() throws RemoteException;
}

        

          import java.util.*;
          import java.io.*;
          public class cookiees{
              public static void main(String []args)
              {
                  Map cookie=new HashMap<>();
                  cookie.put("1","Amaan");
                  cookie.put("2","Amaan2");
                  cookie.put("3","Amaan3");
                  for(Map.Entry uoo: cookie.entrySet())
                  {
                      System.out.println("cookie key : "+ uoo.getKey());
                      System.out.println("cookie value: "+ uoo.getValue());
                  }
              }
          }
        

          
import java.util.*; import javax.mail.*; import javax.mail.internet.*; import javax.activation.*; public class SendMail { public static void main(String [] args){ String to = "chinnasamyponnusamy@gmail.com";//change accordingly String from = "chinna@mlrinstitutions.ac.in";//change accordingly String host = "localhost";//or IP address //Get the session object Properties properties = System.getProperties(); properties.setProperty("mail.smtp.host", host); Session session = Session.getDefaultInstance(properties); //compose the message try{ MimeMessage message = new MimeMessage(session); message.setFrom(new InternetAddress(from)); message.addRecipient(Message.RecipientType.TO,new InternetAddress(to)); message.setSubject("Ping"); message.setText("Hello, this is example of sending email "); // Send message Transport.send(message); System.out.println("message sent successfully. "); }catch (MessagingException mex) {mex.printStackTrace();} } }

//DistanceVectorRouting import java.util.Arrays; public class DistanceVectorRouting { static final int INFINITY = Integer.MAX_VALUE; static final int NUM_NODES = 4; // Number of nodes in the network public static void main(String[] args) { int[][] distanceMatrix = { {0, 1, 3, INFINITY}, // Distance from Node 0 to other nodes {1, 0, INFINITY, 2}, // Distance from Node 1 to other nodes {3, INFINITY, 0, 2}, // Distance from Node 2 to other nodes {INFINITY, 2, 2, 0} // Distance from Node 3 to other nodes }; // Initialize distance vector table int[][] distanceVectorTable = new int[NUM_NODES][NUM_NODES]; for (int i = 0; i < NUM_NODES; i++) { distanceVectorTable[i] = Arrays.copyOf(distanceMatrix[i], NUM_NODES); } System.out.println("Initial Distance Vector Table:"); printDistanceVectorTable(distanceVectorTable); // Simulate iterations of the Distance Vector Routing algorithm for (int i = 0; i < NUM_NODES; i++) { System.out.println("Iteration " + (i + 1) + ":"); for (int j = 0; j < NUM_NODES; j++) { if (j != i) { for (int k = 0; k < NUM_NODES; k++) { if (k != i && distanceVectorTable[j][k] > distanceMatrix[j][i] + distanceVectorTable[i][k]) { distanceVectorTable[j][k] = distanceMatrix[j][i] + distanceVectorTable[i][k]; } } } } printDistanceVectorTable(distanceVectorTable); } } static void printDistanceVectorTable(int[][] distanceVectorTable) { for (int i = 0; i < NUM_NODES; i++) { for (int j = 0; j < NUM_NODES; j++) { System.out.print((distanceVectorTable[i][j] == INFINITY ? "INF" : distanceVectorTable[i][j]) + "\t"); } System.out.println(); } System.out.println(); } } To Run Javac DistanceVectorRouting.java Java DistanceVectorRouting //LinkStateRouting import java.util.*; public class LinkStateRouting { static final int NUM_NODES = 5; // Number of nodes in the network public static void main(String[] args) { int[][] adjacencyMatrix = { {0, 2, 0, 1, 0}, // Adjacency matrix representing links between nodes {2, 0, 3, 2, 0}, {0, 3, 0, 0, 1}, {1, 2, 0, 0, 4}, {0, 0, 1, 4, 0} }; // Initialize link state database int[][] linkStateDatabase = new int[NUM_NODES][NUM_NODES]; for (int i = 0; i < NUM_NODES; i++) { for (int j = 0; j < NUM_NODES; j++) { if (i == j) { linkStateDatabase[i][j] = 0; } else if (adjacencyMatrix[i][j] != 0) { linkStateDatabase[i][j] = adjacencyMatrix[i][j]; } else { linkStateDatabase[i][j] = Integer.MAX_VALUE; } } } System.out.println("Initial Link State Database:"); printLinkStateDatabase(linkStateDatabase); // Simulate iterations of the Link State Routing algorithm for (int i = 0; i < NUM_NODES; i++) { System.out.println("Iteration " + (i + 1) + ":"); for (int j = 0; j < NUM_NODES; j++) { if (j != i) { for (int k = 0; k < NUM_NODES; k++) { if (k != i && linkStateDatabase[j][i] != Integer.MAX_VALUE && linkStateDatabase[i][k] != Integer.MAX_VALUE && linkStateDatabase[j][k] > linkStateDatabase[j][i] + linkStateDatabase[i][k]) { linkStateDatabase[j][k] = linkStateDatabase[j][i] + linkStateDatabase[i][k]; } } } } printLinkStateDatabase(linkStateDatabase); } } static void printLinkStateDatabase(int[][] linkStateDatabase) { for (int i = 0; i < NUM_NODES; i++) { for (int j = 0; j < NUM_NODES; j++) { System.out.print((linkStateDatabase[i][j] == Integer.MAX_VALUE ? "INF" : linkStateDatabase[i][j]) + "\t"); } System.out.println(); } System.out.println(); } } //To Run //Javac LinkStateRouting.java //Java LinkStateRouting

          GENERAL COMMANDS:
Start the docker daemon
docker -d
Get help with Docker. Can also use –help on all subcommands
docker --help
Display system-wide information
docker info
IMAGES:
Docker images are a lightweight, standalone, executable package of software that includes
everything needed to run an application: code, runtime, system tools, system libraries and
settings.
Build an Image from a Dockerfile
docker build -t 
Build an Image from a Dockerfile without the cachedocker build -t  . –no-cache
  List local images
  docker images
  Delete an Image
  docker rmi 
  Remove all unused images
  docker image prune
  CONTAINERS:
  A container is a runtime instance of a docker image. A container will always run the same,
  regardless of the infrastructure. Containers isolate software from its environment and
  ensure that it works uniformly despite differences for instance between development and
  staging.
  Create and run a container from an image, with a custom name:
  docker run –name  
  Run a container with and publish a container’s port(s) to the host.
  docker run -p  :  
  Run a container in the background
  docker run -d 
  Start or stop an existing container:
  docker start|stop  (or )
  Remove a stopped container:
  docker rm 
  Open a shell inside a running container:
  docker exec -it  sh
  Fetch and follow the logs of a container:
  docker logs -f 
  To inspect a running container:
  docker inspect  (or )
  To list currently running containers:
  docker ps
  List all docker containers (running and stopped):
  60
  docker ps --all
  View resource usage stats
  docker container stats