Package data

Examples of data.Bernoulli


        String tip = req.getParameter("tip");
        String host = req.getParameter("host").trim();
        String sPort = req.getParameter("port");
        int port = Integer.parseInt(sPort);
        int n = Integer.parseInt(sn);
        Bernoulli bernoulli = null;
        PrintWriter out = res.getWriter();

        try {
            Interface obj = (Interface)Naming.lookup("//"+host+":"+port+"/Bernoulli");
            bernoulli = obj.bernoulli(n);
        }
        catch (Exception e) {
            System.out.println(e.getMessage());
            System.exit(1);
        }

        if (tip.equals("text/html")) {
            String title = "Bernoulli Servlet RMI";
            res.setContentType("text/html");
            out.println("<!DOCTYPE HTML><html><head><title>");
            out.println(title);
            out.println("</title></head><body>");
            out.println("<h1>"+title+"</h1>");
            out.println("<p>Bernoulli for N="+n+" is:<br>"+bernoulli.asHtml()+"</p>");
            out.println("</body></html>");
        } else {
            res.setContentType("text/plain");
            out.println(bernoulli.asString());
        }
        out.close();
    }
View Full Code Here


public class Servlet extends HttpServlet {
    public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
        String sn = req.getParameter("n");
        String tip = req.getParameter("tip");
        int n = Integer.parseInt(sn);
        Bernoulli bernoulli = new Bernoulli(n);
        PrintWriter out = res.getWriter();
        if (tip.equals("text/html")) {
            String title = "Bernoulli Servlet";
            res.setContentType("text/html");
            out.println("<!DOCTYPE HTML><html><head><title>");
            out.println(title);
            out.println("</title></head><body>");
            out.println("<h1>"+title+"</h1>");
            out.println("<p>Bernoulli for N="+n+" is:<br>"+bernoulli.asHtml()+"</p>");
            out.println("</body></html>");
        } else {
            res.setContentType("text/plain");
            out.println(bernoulli.asString());
        }
        out.close();
    }
View Full Code Here

//import javax.naming.InitialContext;

public class Server implements Interface {

    public Bernoulli bernoulli(int n) {
        return new Bernoulli(n);
    }
View Full Code Here

//            System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.rmi.registry.RegistryContextFactory");
//            System.setProperty(Context.PROVIDER_URL, "rmi://"+host+":"+sPort);
//            Context ctx = new InitialContext();
//            Interface obj = (Interface)ctx.lookup("Bernoulli");

            Bernoulli bernoulli = obj.bernoulli(n);
            bernoulli.print();
        }
        catch (Exception e) {
            System.err.println(e.getMessage());
        }
    }
View Full Code Here

                ByteArrayInputStream bais = new ByteArrayInputStream(bin);
                ObjectInputStream in = new ObjectInputStream(bais);
                int n = in.readInt();
                in.close();
                Bernoulli bernoulli = new Bernoulli(n);

                ByteArrayOutputStream baos = new ByteArrayOutputStream(256);
                ObjectOutputStream out = new ObjectOutputStream(baos);
                out.writeObject(bernoulli);
                out.close();
View Full Code Here

            packet = new DatagramPacket(bin, bin.length);
            socket.receive(packet);

            ByteArrayInputStream bais = new ByteArrayInputStream(bin);
            ObjectInputStream in = new ObjectInputStream(bais);
            Bernoulli bernoulli = (Bernoulli)in.readObject();
            in.close();
            bernoulli.print();
            socket.close();
        }
        catch(Exception e) {
            System.err.println("Client communication error: "+e.getMessage());
        }
View Full Code Here

    public void setN(int n) {
        this.n = n;
    }

    public String getBernoulliAsHtml() {
        Bernoulli bernoulli = new Bernoulli(this.n);
        return bernoulli.asHtml();
    }
View Full Code Here

            try(Socket socket = serverSocket.accept();
                ObjectOutputStream out = new ObjectOutputStream(socket.getOutputStream());
                ObjectInputStream in = new ObjectInputStream(socket.getInputStream())
            ) {
                int n = in.readInt();
                Bernoulli bernoulli = new Bernoulli(n);
                out.writeObject(bernoulli);
                socket.close();
            }
            catch(IOException e) {
                System.err.println("Server communication error: "+e.getMessage());
View Full Code Here

            ObjectOutputStream out = new ObjectOutputStream(socket.getOutputStream())
        ) {
            out.writeInt(n);
            out.flush();

            Bernoulli bernoulli = (Bernoulli)in.readObject();
            bernoulli.print();
            socket.close();
        }
        catch(Exception e){
            System.err.println("Client communication error: "+e.getMessage());
        }
View Full Code Here

        while(true) {
            try(SocketChannel socketChannel = serverSocketChannel.accept()) {
                ByteBuffer bb = ByteBuffer.allocate(2048);
                socketChannel.read(bb);
                int n = bb.getInt(0);
                Bernoulli bernoulli = new Bernoulli(n);

                ByteArrayOutputStream baos = new ByteArrayOutputStream(256);
                ObjectOutputStream out = new ObjectOutputStream(baos);
                out.writeObject(bernoulli);
                byte[] bout = baos.toByteArray();
View Full Code Here

TOP

Related Classes of data.Bernoulli

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.