RMI or sockets

I was asking for help on the design of a network-aware application. Let me give a description of the program i need.
I want an application that does stock or inventory management in a warehouse. It should be developed in Java and use JDBC connection to database rather than ODBC. The database will have many tables like users, stocks, transactions, accounts and others. The application needs to have only one version of data hence the database will be connected to the server and clients will be geting the recordsets and other objects from the server after sending requests to it. No process need be done in the server only that the server gives authentication and other services.There might also be a some computers that will be connected to the server using telephone extensions through a PABX. The server should have a capability to post some results to the web through URLConnection of which is not a problem.
So the question is if i use sockets will it be effective or must i use RMI. I need no CORBA because the server and the client are developed in Java.

RMI will be much easier for Java 2 Java communication. With sockets if you are sending data back and forth or want to invoke remote methods you will endup having to deal with marshalling and unmarshalling of parameters etc..

Similar Messages

  • What is the advantage of using RMI over socket connection

    plz tell me guys what is the advantage of using RMI over socket connection bcoz inherently RMI also uses socket connection.so what is the exact difference in between thm and what is the advantage of using RMI over socket connection.

    i knew tht bt i http://www.catb.org/~esr/faqs/smart-questions.html#writewell
    How To Ask Questions The Smart Way
    Eric Steven Raymond
    Rick Moen
    Write in clear, grammatical, correctly-spelled language
    We've found by experience that people who are careless and sloppy writers are usually also careless and sloppy at thinking and coding (often enough to bet on, anyway). Answering questions for careless and sloppy thinkers is not rewarding; we'd rather spend our time elsewhere.
    So expressing your question clearly and well is important. If you can't be bothered to do that, we can't be bothered to pay attention. Spend the extra effort to polish your language. It doesn't have to be stiff or formal — in fact, hacker culture values informal, slangy and humorous language used with precision. But it has to be precise; there has to be some indication that you're thinking and paying attention.
    Spell, punctuate, and capitalize correctly. Don't confuse "its" with "it's", "loose" with "lose", or "discrete" with "discreet". Don't TYPE IN ALL CAPS; this is read as shouting and considered rude. (All-smalls is only slightly less annoying, as it's difficult to read. Alan Cox can get away with it, but you can't.)
    More generally, if you write like a semi-literate b o o b you will very likely be ignored. So don't use instant-messaging shortcuts. Spelling "you" as "u" makes you look like a semi-literate b o o b to save two entire keystrokes.

  • Applet-Servlet communication in RMI or sockets

    As a dissertation piece I am creating a game to be played by multiple players accross the internet using servlets. However I am having great difficulty figuring out how to use RMI or sockets within servlets (I already have the socket-based code). I also can't seem to find many books or sites out there which might help. If anyone outthere has done this type of thing before or can advise any reading material I would be very grateful

    Write a servlet and in the web.xml have the servlet load on server start-up.
    In the servlet have a thread start in the init method. The thread will start a socket server that the applets can connect to. The socket server can be the standard socket server as outlined in the tutorial:
    http://java.sun.com/docs/books/tutorial/networking/sockets/index.html

  • JBoss + java.rmi.MarshalException: Socket timed out

    Hello.
    I'm not author of the software, I've just been transfered to try solve this problem:
    I've got an client application, an server app, JBoss, and Oracle DB.
    Now, when i try to create a big report in xls, which usually takes over 30minutes i get the exception:
    pl.wasko.serloc.DelegateException: Utracono po��czenie z serwerem.
    Spr�buj ponowi� operacj�
         at pl.wasko.mra.template.delegate.DocumentDelegate.unknownException(DocumentDelegate.java:74)
         at pl.wasko.mra.template.delegate.DocumentDelegate.exportToXls(DocumentDelegate.java:590)
         at pl.wasko.mra.client.task.ExportTemplateToFileTask.<init>(ExportTemplateToFileTask.java:71)
         at pl.wasko.mra.client.document.DocumentAdministration$11.construct(DocumentAdministration.java:447)
         at pl.wasko.mra.client.task.SwingWorker$2.run(SwingWorker.java:146)
         at java.lang.Thread.run(Thread.java:595)
    Caused by: java.rmi.MarshalException: Socket timed out.  Waited 1800000 milliseconds for response while calling on InvokerLocator [socket://193.178.240.21:3873/]; nested exception is:
         java.net.SocketTimeoutException: Read timed out
         at org.jboss.remoting.transport.socket.SocketClientInvoker.transport(SocketClientInvoker.java:302)
         at org.jboss.remoting.RemoteClientInvoker.invoke(RemoteClientInvoker.java:143)
         at org.jboss.remoting.Client.invoke(Client.java:525)
         at org.jboss.remoting.Client.invoke(Client.java:488)
         at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:55)
         at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
         at org.jboss.aspects.tx.ClientTxPropagationInterceptor.invoke(ClientTxPropagationInterceptor.java:61)
         at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
         at org.jboss.aspects.security.SecurityClientInterceptor.invoke(SecurityClientInterceptor.java:55)
         at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
         at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:65)
         at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
         at org.jboss.ejb3.stateless.StatelessRemoteProxy.invoke(StatelessRemoteProxy.java:102)
         at $Proxy1.exportTemplateToXlsByteArray(Unknown Source)
         at pl.wasko.mra.template.delegate.DocumentDelegate.exportToXls(DocumentDelegate.java:581)
         ... 4 more
    Caused by: java.net.SocketTimeoutException: Read timed out
         at java.net.SocketInputStream.socketRead0(Native Method)
         at java.net.SocketInputStream.read(SocketInputStream.java:129)
         at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
         at java.io.BufferedInputStream.read(BufferedInputStream.java:235)
         at java.io.ObjectInputStream$PeekInputStream.peek(ObjectInputStream.java:2200)
         at java.io.ObjectInputStream$BlockDataInputStream.peek(ObjectInputStream.java:2490)
         at java.io.ObjectInputStream$BlockDataInputStream.peekByte(ObjectInputStream.java:2500)
         at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1267)
         at java.io.ObjectInputStream.readObject(ObjectInputStream.java:339)
         at org.jboss.remoting.serialization.impl.java.JavaSerializationManager.receiveObject(JavaSerializationManager.java:128)
         at org.jboss.remoting.marshal.serializable.SerializableUnMarshaller.read(SerializableUnMarshaller.java:66)
         at org.jboss.remoting.transport.socket.SocketClientInvoker.transport(SocketClientInvoker.java:279)
         ... 18 moreProblem is that I'm not the author of this program, program is old, and the author learned on it, so it's code is illegible (I mean dificult to debug, and even read).
    I've only discovered that it uses Jasper to generate raport (I think so... I don't know), trace ended here:
    JasperConversion conv = new JasperConversion();                 
          JasperPrint jasperPrint = conv.createJasperPrint(template,params,searchCompileReport,userId, reportPagination);
          String test = System.getProperty("pl.wasko.mra.template.test");
          if(test != null && test.equals("1"))
            String tempDir = System.getProperty("jasper.reports.compile.temp");
            if(tempDir != null)
              conv.exportToPdfFile(jasperPrint,tempDir+"/test.xls");
          }I really don't ahve any ideas, I've tried to edit xml files on jboss - no result, properties files - the same, I was looking for something in the code to change timeout, but without results.
    Please, if anyone had similar problem, or have an idea, how to fix this, I will be very gratefull

    if you are using jboss 4+ and ejb3, ib believe you want to edit the "ejb3.deployer/META-INF/jboss-service.xml" file. you want to change the "InvokerLocator" attribure on the "jboss.remoting:type=Connector,name=DefaultEjb3Connector,handler=ejb3" mbean. it should currently look like "socket://${jboss.bind.address}:3873". you want to add a "timeout" attribute like "socket://${jboss.bind.address}:3873/?timeout=yourTimeoutHere", where "yourTimeoutHere" is your desired timeout in milliseconds.

  • RMI or Sockets Prog???

    I want to send a .jar file from server to client and want to store it at a particular location there! Can anybody tell me which would be preferable , whether RMI or Socket Prog???

    i'd probably use http over sockets. It makes it easy to test your server & client impl.

  • Chat App. RMI or sockets?

    I have to make a chat (client/server) application, and i'm asking you an advice. I'm new in Java. I looked for some info and i found that there are 2 ways for do that RMI or sockets.
    Which is better? Please answer me.
    If anybody can explain me(or give me a link) the difference between these techs.
    Thanks a lot

    The question is why are you making a chat program? If it's to learn, then do both :). If you do it with sockets you will create the "Protocol" between the client & server. If you do it with RMI you call methods on the server from the client or vise versa as if there was no network involved. You won't understand the answer to your question until you try both.

  • When does the RMI Client socket be created?

    Hi, I have created my own RMIClientSocketFactory and RMIServerSocketFactory, it was just a normal socket with some print statements. Example:
    ============================================================
    public class MyRMIClientSocketFactory implements
    RMIClientSocketFactory, Serializable {
    private int hashCode = "MyRMIClientSocketFactory".hashCode();
    public Socket createSocket(String host, int port) throws IOException {
    System.out.println("creating socket to host : " + host + " on port " + port);
    return new Socket(host, port);
    public boolean equals(Object object) {
    if (object instanceof MyRMIClientSocketFactory)
    return true;
    return false;
    public int hashCode() {
    return hashCode;
    public class MyRMIServerSocketFactory implements RMIServerSocketFactory, Serializable {
    private int hashCode = "MyRMIServerSocketFactory".hashCode();
    public ServerSocket createServerSocket(int port) throws IOException {
    System.out.println("creating ServerSocket on port " + port);
    return new ServerSocket(port);
    public boolean equals(Object object) {
    if (object instanceof MyRMIServerSocketFactory)
    return true;
    return false;
    public int hashCode() {
    return hashCode;
    ================================================================
    I wonder when the message "creating socket on port.." and "creating ServerSocket on port.." will be printed? And I found that the equals() and hashCode() methods are called quite a lot of times when I made one rmi call. When I keep the reference of the remote object for some times, the client socket will be created again. Can somebody tell me how all these work?
    Thanks,
    Jax

    Does it
    means that when timeout happened, a new client socket
    will be created and make remote calls to renew DGC
    leases?Yes.
    Again, about exporting remote objects on the same
    port, why I got the exceptions:
    java.rmi.server.ExportException: Port already in use:
    1234;
    nested exception is: java.net.BindException: Address
    already in use: JVM_BindYou get this if you try to export two servers on the same port but their server socket factories are not equal (or not both null or unspecified), or if the two ojbects are in separate JVMs (port sharing can only work inside a single JVM), or if the port is in use by some other listening process.
    Your MyRMIServerSocketFactory.equals() method looks OK to me, but I'd delete the hashCode() method, it's not necessary for RMI and your implementation is flawed. Personally I use the following equals() method:
    public boolean equals(Object that) { return that != null && that.getClass() == this.getClass(); }

  • Web services, RMI or Sockets?

    hi all,
    we have a need to develop a J2SE V5.0 system consisting of:
    a) Stand-along Java application acting as a real-time I/O data server;
    b) Applets acting as client.
    The data server provides real-time data to the Applet, so the client can see values changing on the web browser. Both real-time data server and Web server/Applets are stored on the same computer hardware machine.
    Question:
    1) What is the best technology to be used for the Ethernet TCP/IP communications between the data server and the Applet client.
    thanks in advance.
    Trajano Roberto

    For the transmittion of data I would suggest sending a data stream from the server via socket.
    This is very simple to achieve compared with RMI.
    However, if you need the applet to perform requests for the server this is best acheived using RMI (or the like). Even if you don't need it now, you may need it in the future for this reason.
    Personally, my preference is to use both for the different purposes.

  • When does RMI create sockets

    Hi
    Is the following sentence correct: "Creating an instance of a class that extends UnicastRemoteObject does not create any sockets. Creation of sockets is not done before the instance is registered with a Registry".
    Soeren Mors

    From the RMI FAQ:
    http://java.sun.com/products/jdk/1.2/docs/guide/rmi/faq.html#connection
    F.1 At what point is there a "live" connection between the client and the server and how are connections managed?
    When a client does a "lookup" operation, a connection is made to the rmiregistry on the specified host. In general, a new connection may or may not be created for a remote call. Connections are cached by the RMI-transport for future use, so if a connection is free to the right destination for a remote call, then it is used. A client cannot explicitly close a connection to a server, since connections are managed at the RMI-transport level. Connections will time out if they are unused for a period of time.
    F.5 Is there only one socket connection between a client process and the server, no matter how many stubs exist in that client process?
    RMI reuses the socket connections between client and server whenever possible. The current implementation creates additional sockets on demand when they are needed. For example, if the existing socket is in use by a call then a new socket is created for the new call. Typically, there are at least two sockets open since the distributed garbage collector needs to make remote calls when remote objects are returned from the server. If a cached connection remains unused for a period of time, the connection is closed.

  • Which technology to implement RPC or RMI or Socket?

    I'm developing a 2 players card game in java.
    I want to implement it on remote computers. i.e. one player will play on the local machine and the other player will play on remote computer which could be on Internet.
    Both the players will be having the same game application and same set of methods and variables.
    Also this game needs to be completely platform independent.
    What technology should i implement for the above requirement.
    I'm new to Java and net programming so an elaborate suggestion would be better.
    Thanking you.

    user10444163 wrote:
    I'm new to Java and net programming so an elaborate suggestion would be better.If you're new to Java programming, it's too early to start writing a 2 player networked game.
    You'll need to spend 6-12 months learning Java first (including networking and other aspects). During that time you'll see for yourself when you're ready to tackle projects like this.
    Well you edited your post after my reply, so I'll edit my answer as well.
    From the three choices in the title, I would suggest Sockets. It's the most straight forward choice and that's what all the other protocols are based on. Makes sense to learn from the beginning.
    Edited by: Kayaman on Jan 30, 2011 11:43 AM

  • Sockets in rmi, help needed

    hi,
    I need a help on using sockets in rmi for communication between the server and the client. I am trying to establish a communication between the server and client through sockets after the remote method call is invoked but before it is fulfilled. I my code the socket is not establishing in the client side. Do help me out at the earliest pls... thanks in advance..

    I am trying to use sockets inside a rmi. Still i have the problem. I cant get my client listen from the server.
    First the client invokes a remote object. Before server sending the actual request of the requested by the remote object i want to make some communication between the server and client through sockets.
    I created a ServerSocket in the client side. The problem I have is the ServerSocket is not listening to the server request.
    Here i ve my code.I cant figure out what mistake i have done. It also dont show any error. As i am new to RMI and sockets i am in need of help. So pls do help me... Thanks in advance.
    In my example i am trying to verify the password before the server downloads the file for the client. So i want the verification done through sockets and download file using RMI.
    FileInterface.java
    import java.rmi.*;
    public interface FileInterface extends Remote
    public byte[] downloadFile(String fileName) throws RemoteException;
    FileServer.java
    import java.rmi.*;
    import java.io.*;
    public class FileServer
    public static void main(String []args)
      if(System.getSecurityManager()==null)
       System.setSecurityManager(new RMISecurityManager());
      try
       FileImpl fi=new FileImpl("FileServer");
       Naming.rebind("FileServer",fi);
         System.out.println("Server bound"+fi);
      catch(Exception e)
       System.out.println("FileServer: "+e.getMessage());
    FileImpl.java
    import java.io.*;
    import java.net.*;
    import java.rmi.*;
    import java.rmi.server.UnicastRemoteObject;
    public class FileImpl extends UnicastRemoteObject implements FileInterface
    private String name;
    public FileImpl(String s) throws RemoteException
      super();
      name=s;
    public byte[] downloadFile(String fileName)
      try
       Socket soc=new Socket(RemoteServer.getClientHost(),5000);
       OutputStream os=soc.getOutputStream();
       PrintStream ps=new PrintStream(os);
         System.out.println("Going to send message");
       ps.println("Enter the password : ");
         System.out.println("Sent message");
       InputStream is=soc.getInputStream();
       InputStreamReader isr=new InputStreamReader(is);
       BufferedReader br=new BufferedReader(isr);
       String res=br.readLine();
       PasswordControl pc=new PasswordControl(res,br);
       System.setSecurityManager(pc);
       File file=new File(fileName);
       byte [] buffer=new byte[(int)file.length()];
       BufferedInputStream input=new BufferedInputStream(new FileInputStream(fileName));
       input.read(buffer,0,buffer.length);
       input.close();
       return(buffer);
      catch(Exception e)
       System.out.println("FileImpl: "+e.getMessage());
       e.printStackTrace();
       return(null);
    public class PasswordControl extends SecurityManager
    String password;
    BufferedReader br;
    public PasswordControl(String password,BufferedReader br)
      this.password=password;
      this.br=br;
    public boolean accessOk()
      String response = "";
      try
       if(response.equals(password))
        return true;
       else
        return false;
      catch(Exception e)
       return false;
    public void checkRead(String fname)
      if(fname.equals("sample.txt"))
       if(!accessOk())
        super.checkRead(fname);
        throw new SecurityException("Access denied to read from the file sample.txt");
       else
        FilePermission fp=new FilePermission(fname,"read");
        checkPermission(fp);
    FileClient.java
    import java.io.*;
    import java.net.*;
    import java.rmi.*;
    public class FileClient  implements Runnable {
         Socket soc;
         String filename;
         byte[] filedata;
         public FileClient(String filename, String host)
         this.filename = filename;
         try
             ServerSocket ss=new ServerSocket(5000);
          System.out.println("Created a socket"+ss);
             String name = "//" + host + "/FileServer";
             FileInterface fi = (FileInterface) Naming.lookup(name);
          System.out.println("Got the interface "+fi);
             while(true)
           soc=ss.accept();
           new Thread(this).start();
            } catch(Exception e)
              e.printStackTrace();
           public static void main(String argv[]) {
            if(argv.length != 2) {
            System.out.println("Usage: java FileClient fileName machineName");
            System.exit(0);
         new FileClient(argv[0], argv[1]);
         public void run() {
         try {
         System.out.println(soc);
          InputStream is=soc.getInputStream();
          InputStreamReader isr=new InputStreamReader(is);
             BufferedReader br=new BufferedReader(isr);
         System.out.println("Created the readers"+br);
             String req=br.readLine();
          System.out.println("Going to print request");
          System.out.println(req);
          String password=br.readLine();
             OutputStream os=soc.getOutputStream();
          PrintStream ps=new PrintStream(os);
          ps.println(password);
             filedata = fi.downloadFile(filename);
             File file = new File(filename);
             BufferedOutputStream output = new
               BufferedOutputStream(new FileOutputStream(file.getName()));
             output.write(filedata,0,filedata.length);
             output.flush();
             output.close();
         } catch(Exception e) {
              e.printStackTrace();
    }

  • Can we use applets as user interfaces with sockets, RMI and J2EE

    Dear Sir or Madam,
    Since I am a TA for software architecture class, some one ask me the following question: I think the answer is "No" based on the document on http://java.sun.com/sfaq/
    How I answer the quesions? Looking forward your help!!!
    1.You may have 2 applets and 2 html files. One applet with one html file may stay at a client PC and run on this PC, and the other applet with the other html file may stay at a server PC and run on this PC. In this case, all the applets are run locally.
    2.Could applets works with sockets, RMI and J2EE?
    3.Can we use applets as user interfaces with sockets, RMI and J2EE?
    Thank you very much!
    Best regards,
    Jing

    The scenario you paint doesn't quite make sense. The "server PC" wouldn't be running an applet, normally, since applets are by definition in a web browser page, and most likely involve user interaction, and "server processes" generally are done without user interaction.
    The security rules around applets are that -- by default -- applets can connect with sockets ONLY to the server from whence the applet was loaded. RMI uses sockets (J2EE is too broad a spec) and hence RMI calls would also be limited to the server from whence the applet was loaded. Within that limitation, an applet could open all the sockets it wants, so long as they are all on the server from whence the applet was loaded.
    If you want two applets on two different systems to communicate with each other, the simplest way is to have them rendevous through a server process on the server(s) from whence each applet was loaded. Maybe it's PC-a <-> server-a <-> server-b <-> PC-b ...? Or maybe PC-a and PC-b both are talking to the same server.
    The limitation is rooted in the security subsystem. You can specify a policy file and override anything in the security subsystem. That does mean signing the applet and then cajoling the user into agreeing to grant greater levels of security than the default. In such a case you can open sockets more broadly and then PC-a could talk directly to PC-b without going through any servers.
    - David

  • Socket Or RMI for the best solution

    Do me a favor guys...help me to figure this out, which the best solution of this, i create some networks, what i plan is like this..
    if client send their request to appServer which using web browser, the request will arrive to the appServer,right? and then i create some network application to forward the request to another computer to be process, and response the client... the problem are :
    1. which is more efficient, faster,reliabe and secure ,create socket and i put the socket on My RMI or only using socket?
    2. if i combine both RMI and Socket, is that good or not? why?
    Thank u so much for answer....

    Is that much more easier to implement using RMI? why? if i only use Socket,how about the connection,is that slower than RMI or not? and how about the security problem?
    will have problem with RMI if u client behind Firewall or proxy.is that true? how to handle this? how can this could be happen?

  • RMI and Traditional network socket programming

    Friends,
    Please help me
    What is the advantage of RMI over socket programming ?

    you may need to refer to a good RMI book for having a detailed answer. Since they are quite a few of em.

  • Using RMI from another language

    I've been playing around with an idea of connecting to some Java library with RMI from a another programming language.
    I know that deep inside RMI uses sockets to send the data, so any language supporting sockets should be able to use RMI as well, it's a matter of creating the protocol for that language x.
    Does anyone if there's a library like this for any language?
    Is the RMI protocol free for studying? I found a couple of articles on RMI internals, but they don't go into this much of details.
    [http://www.developer.com/article.php/10915_3455311_3/Understanding-Java-RMI-Internals.htm|http://www.developer.com/article.php/10915_3455311_3/Understanding-Java-RMI-Internals.htm]
    [http://java.sun.com/developer/onlineTraining/rmi/RMI.html|http://java.sun.com/developer/onlineTraining/rmi/RMI.html]

    dave_spaghetti wrote:
    jtahlborn wrote:
    dave_spaghetti wrote:
    jtahlborn wrote:
    dave_spaghetti wrote:
    The RMI-IIOP sounds good, but the language(Flex/ActionScript) I was first thinking about does not have a CORBA support. Another need for an open source project maybe. I'll have to learn more about CORBA to see how complicated it is.doesn't flex/actionscript already have a java binding api?There's BlazeDS and GraniteDs, if that's what you meant. Those are Java EE apps running on top of an application server
    I'm thinking of something running local machine only. And like I said, I'm just thinking whether it would be possible at all.
    Edited by: dave_spaghetti on Mar 26, 2010 12:02 PMyes, that's what i was thinking of. the graniteds web page claims it runs on standalone tomcat or jetty. jetty is pretty lightweight. if it were me, i'd look at using these existing libraries before reinventing a (rather complex) wheel.Thanks for the reply and sorry for my reply coming so late.
    These are very valuable notes. I'll consider them. I think at least Tomcat has something called "embedded mode", which could be useful here.jetty has an embedded mode as well, we use it that way in our product. works great.

Maybe you are looking for