Results 1 to 2 of 2
  1. #1
    prince87 is offline Member
    Join Date
    Apr 2011
    Posts
    1
    Rep Power
    0

    Default MultiClient with Single Server

    Hello Every body can someone Help to correct me. This is RMI with Multiclient and single server. it give error at SubtractImpl as I underline at that bit. and When I run it as whole. it say connection refused It is very Important. Thank u....

    It is My Interface

    public class subtractImpl extends UnicastRemoteObject
    implements subtractInterface
    {
    /**
    *
    */
    private static final long serialVersionUID = 7458753050293118586L;

    public subtractImpl(String name) throws RemoteException
    {
    super();
    try
    {
    Naming.rebind(name,this);
    }
    catch(Exception e) { }
    }

    public int find_subtract(int n1,int n2) throws RemoteException
    {
    int ans=0;
    ans = n1-n2;
    return ans;
    }

    }


    It is My Client


    public class subtractClient
    {

    public static void main(String args[])

    {

    Socket ClientSocket = null;
    PrintWriter out = null;

    try {

    ClientSocket = new Socket("127.0.0.1", 1111);
    out = new PrintWriter(ClientSocket.getOutputStream(), true);
    }
    catch (UnknownHostException e)
    {
    System.err.println("Unknown host " + e);
    System.exit(1);
    }
    catch (IOException e)
    {
    System.err.println("I/O Exception " + e);
    System.exit(1);

    }


    System.setSecurityManager(new RMISecurityManager());

    try
    {

    int ans;
    int intNumber1 = 0;
    int intNumber2 = 0;
    subtractInterface pi = (subtractInterface) Naming.lookup("//127.0.1/1111");
    DataInputStream in = new DataInputStream(System.in);;

    System.out.print("Enter Number 1 : ");
    intNumber1 = Integer.parseInt(in.readLine());

    System.out.print("Enter Number 2 : ");
    intNumber2 = Integer.parseInt(in.readLine());

    ans = pi.find_subtract(intNumber1,intNumber2);
    System.out.println(ans);
    }
    catch(Exception e) { }
    }
    }

    It is Server with MultiThreading
    public class subtractServer
    {
    private static int port = 1102, maxConnections = 10;
    // Listen for incoming connections and handle them
    public static void main(String[] args, ServerSocket listner) {
    int i=0;

    try{
    System.setSecurityManager(new RMISecurityManager());
    ServerSocket listener = new ServerSocket(1111);
    Socket server;

    while((i++ < maxConnections) || (maxConnections == 10)){


    server = listener.accept();
    doComms conn_c= new doComms(server);
    Thread t = new Thread(conn_c);
    t.start();
    }
    } catch (IOException ioe) {
    System.out.println("IOException on socket listen: " + ioe);
    ioe.printStackTrace();
    }
    }
    private static void listner() {
    // TODO Auto-generated method stub

    }
    public static void setPort(int port) {
    subtractServer.port = port;
    }
    public static int getPort() {
    return port;
    }

    }

    class doComms implements Runnable {
    private Socket subtractserver;
    private String input;

    doComms(Socket subtractserver) {
    this.subtractserver=subtractserver;
    }

    public void run () {

    input="";


    try {

    // Get input from the client
    subtractImpl pim = new subtractImpl("//127.0.0.1/1111");
    System.out.println("\nServer is ready...");
    subtractserver.close();
    }
    catch (IOException ioe) {
    System.out.println("IOException on socket listen: " + ioe);
    ioe.printStackTrace();
    }
    }
    }
    Last edited by prince87; 05-01-2011 at 10:08 AM. Reason: Putting code in [code]/* */[/cod]

  2. #2
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default

    Please post formatted code in code tags... like this but without the spaces inside the brackets:

    [ code] /* your code here */ [ /code]

Similar Threads

  1. multiple clients single server via sockets
    By acks in forum Networking
    Replies: 3
    Last Post: 04-12-2011, 08:44 AM
  2. Replies: 1
    Last Post: 10-26-2010, 12:21 AM
  3. multiclient copy
    By thuyduong89dt in forum Networking
    Replies: 0
    Last Post: 12-04-2009, 02:46 PM
  4. Replies: 1
    Last Post: 10-02-2008, 08:02 PM
  5. Minimal single threaded web server?
    By johann_p in forum New To Java
    Replies: 2
    Last Post: 04-24-2008, 05:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •