Run multiple clients and one server

Assignment Help Programming Languages
Reference no: EM13306267

Assignment that requires to run multiple clients and one server ( Corba)

This file might help you to create your client side and server .

import Inter.*;

import java.util.Vector;

import java.util.Iterator;

 

public class DBControlServerImpl extends DBControlServerPOA

{

    private Vector clients = new Vector(); // The clients currently connected

    private CallingThread ct = null;

 

    public DBControlServerImpl()

    {

        ct = new CallingThread(this);

    }

 

    public void requestConnect(DBClientListener dbcl)

    {

        System.out.println("A client has connected.");

        clients.add(dbcl);

    }

 

    public void startCallingThread()

    {

        ct.start();

    }

 

    public int getClientCount()

    {

        return clients.size();

    }

 

    public void sendWorkMessages()

    {

        Iterator it = clients.iterator();

        while (it.hasNext())

        {

            DBClientListener dbcl = (DBClientListener) it.next();

            dbcl.doWork();

        }

    }

}

import Inter.*;

import java.io.BufferedReader;

import java.io.File;

import java.io.FileReader;

 

public class DBClientListenerImpl extends DBClientListenerPOA

{

    public void doWork()

    {

        File rDir = new File(System.getProperty("user.dir"));

        rDir = new File(rDir.getAbsolutePath() + File.separatorChar);

        File inFile = new File(rDir.getAbsolutePath() + File.separatorChar

                + "Database.dat");

        if (inFile.exists())

        {

            try

            {

                BufferedReader in = new BufferedReader(new FileReader(inFile));

                String tmp = ""; // Temp line holder.

                long timeElapsed = 0;

                long startTime = System.currentTimeMillis();

                tmp = in.readLine();

                while (tmp != null)

                {

                    tmp = in.readLine();

                }

                long endTime = System.currentTimeMillis();

                timeElapsed = endTime - startTime;

                System.out.println("Client finished computations on file in "

                        + timeElapsed + " ms.");

            } catch (Exception e)

            {

                e.printStackTrace();

            }

        } else {

            System.out.println("Database file was not found");

        }

    }

}

import org.omg.CORBA.ORB;

import org.omg.PortableServer.POA;

import org.omg.PortableServer.POAHelper;

import Inter.*;

 

public class Client

{

    public static void main(String[] args)

    {

        try

        {

            // initialize orb

            ORB orb = ORB.init(args, null);

            System.out.println("Initialized ORB");

 

            // Instantiate Servant and create reference

            POA rootPOA = POAHelper.narrow(orb

                    .resolve_initial_references("RootPOA"));

            DBClientListenerImpl listener = new DBClientListenerImpl();

            rootPOA.activate_object(listener);

            DBClientListener ref = DBClientListenerHelper.narrow(rootPOA

                    .servant_to_reference(listener));

 

            // Resolve DBControlServer

            DBControlServer dbcServer = DBControlServerHelper

                    .narrow(orb.string_to_object(

                    "corbaname:iiop:1.2@localhost:1050#DBControlServer"));

 

            // Register listener reference (callback object) with MessageServer

            dbcServer.requestConnect(ref);

            System.out.println("Registered with DBControlServer.");

 

            // Activate rootPOA

            rootPOA.the_POAManager().activate();

 

            // Wait for work request

            System.out.println("Waiting for work request.");

            orb.run();

 

        } catch (Exception e)

        {

            e.printStackTrace();

        }

    }

}

import java.io.BufferedReader;

import java.io.InputStreamReader;

 

public class CallingThread extends Thread

{

    DBControlServerImpl dbcsiImpl = null;

 

    public CallingThread(DBControlServerImpl dbcsiImpl)

    {

        this.dbcsiImpl = dbcsiImpl;

    }

 

    public void run()

    {

        int userInput = 0;

        try

        {

            BufferedReader read = new BufferedReader(new InputStreamReader(

                    System.in));

            try

            {

                System.out.print("Please enter the number of clients you wish to connect: ");

                userInput = Integer.parseInt(read.readLine());

                System.out.println("Waiting for " + userInput + " clients to connect...");

            } catch (Exception e)

            {

                e.printStackTrace();

            }

            boolean completed = false;

            for (;;)

            {

                if (dbcsiImpl.getClientCount() >= userInput && !completed)

                {

                    System.out.println(userInput + " clients connected, starting work; check client screens...");

                    dbcsiImpl.sendWorkMessages();

                    completed = true;

                }

            }

        } catch (Exception e)

        {

            e.printStackTrace();

        }

    }

}

import java.io.BufferedReader;

import java.io.InputStreamReader;

 

public class CallingThread extends Thread

{

    DBControlServerImpl dbcsiImpl = null;

 

    public CallingThread(DBControlServerImpl dbcsiImpl)

    {

        this.dbcsiImpl = dbcsiImpl;

    }

 

    public void run()

    {

        int userInput = 0;

        try

        {

            BufferedReader read = new BufferedReader(new InputStreamReader(

                    System.in));

            try

            {

                System.out.print("Please enter the number of clients you wish to connect: ");

                userInput = Integer.parseInt(read.readLine());

                System.out.println("Waiting for " + userInput + " clients to connect...");

            } catch (Exception e)

            {

                e.printStackTrace();

            }

            boolean completed = false;

            for (;;)

            {

                if (dbcsiImpl.getClientCount() >= userInput && !completed)

                {

                    System.out.println(userInput + " clients connected, starting work; check client screens...");

                    dbcsiImpl.sendWorkMessages();

                    completed = true;

                }

            }

        } catch (Exception e)

        {

            e.printStackTrace();

        }

    }

}

Reference no: EM13306267

Questions Cloud

Determine the thermal efficiency of this heat engine : A heat engine using a diatomic ideal gas goes through the following closed cycle: Isothermal compression until the volume is halved. What is the thermal efficiency of this heat engine
What frequency is being emitted by both speakers : Two in phase speakers are set up in a field 10.0 meters apart. you stand directly in between the speakers with one on your left and the other on your right. What frequency is being emitted by both speakers
Characterize multilateral negotiations : 1. What are the three key stages and phases that characterize multilateral negotiations?
Determine the total axil deformation of the shaft : A solid composite shaft is subjected to a 2MN force. Section AB is red brass (E= 120 Gpa), and section BC is AISI 1010 steel (E=200GPa). Find the normal stress in each section and the total axil deformation of the shaft.
Run multiple clients and one server : Run multiple clients and one server - create your client side and server
Where do the pulses first meet : A 10.0-m long wire whose total mass is 39.5 grams is under a tension of 577N. Where do the pulses first meet
List the volcanic hazards associated with shield volcanoes : You have been hired to plan and build a subdivision on the volcanic island of Hawaii. As you know, this island is made of several shielf volcanoes. A) List the volcanic hazards associated with shield volcanoes.
What is probability that the wave height will exceed 6 meter : A nuclear facility in a coastal region is built to withstand ocean wave forces. Suppose the annual maximum wave height of the ocean waves (above the sea level) is a lognormal random variable with mean height of 4.0 meters and a c.o.v. of 0.8
Discuss the benefits of traditional linux file permissions : Discuss the benefits of the traditional Linux file permissions scheme. How might it be superior to permission methodologies employed in other operating systems and what are the differences in overall approach to permissions, privilege, and securit..

Reviews

Write a Review

Programming Languages Questions & Answers

  Write a haskell program to calculates a balanced partition

Write a program in Haskell which calculates a balanced partition of N items where each item has a value between 0 and K such that the difference b/w the sum of the values of first partition,

  Create an application to run in the amazon ec2 service

In this project you will create an application to run in the Amazon EC2 service and you will also create a client that can run on local machine and access your application.

  Explain the process to develop a web page locally

Explain the process to develop a Web page locally

  Write functions

These 14 questions covers java class, Array, link list , generic class.

  Programming assignment

If the user wants to read the input from a file, then the output will also go into a different file . If the user wants to read the input interactively, then the output will go to the screen .

  Write a prolog program using swi proglog

Write a Prolog program using swi proglog

  Create a custom application using eclipse

Create a custom Application Using Eclipse Android Development

  Create a application using the mvc architecture

create a application using the MVC architecture. No scripting elements are allowed in JSP pages.

  Develops bespoke solutions for the rubber industry

Develops bespoke solutions for the rubber industry

  Design a program that models the worms behavior

Design a program that models the worm's behavior.

  Writing a class

Build a class for a type called Fraction

  Design a program that assigns seats on an airplane

Write a program that allows an instructor to keep a grade book and also design and implement a program that assigns seats on an airplane.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd