Making choice between socket and RMI

I never use RMI, but i am familiar to socket programming. i want to write an online game, I know that use RMI will easy than use socket, could anyone tell me what factors will affect the choice between using socket and RMI if don't consider which one i am familiar ?
thanks
jacky

I would consider the amount of traffic your online game is going to be generating. Obviously, if the traffic is the bottleneck, you will want to optimize it as much as possible.
I can see that if you are familiar with sockets and socket programming, where this is very appealing because after all, you can't get much faster than raw sockets. Also, the Java APIs around sockets are much easier than the equivalent BSD Socket C/C++ libraries.
Still, RMI has much more to offer.
o It is relatively easy to set up a connection
o exceptions will be thrown when problems occur
o serializing classes is so easy it's laughable
o If performance becomes an issue, you can (as the previous poster suggests) create your own custom socket factory which optimizes the used bandwidth. Options here include compression if you have the CPU cycles to spare.
o There are mechanisms in place for working RMI over firewalls
Many of the things that RMI offers, you might find yourself re-writing in your own socket-based API. Personally, I would choose RMI.

Similar Messages

  • Conflict between socket and RMI

    Hi
    I wrote a program in client-server using socket and it was fine. I also wrote a client-server program using RMI. Fine as well. But after I connected the client-server using socket (open socket, send-receive messages, close socket), then use RMI. I got java.rmi.NotBoundException.
    Would anyone have a look and provide your feedback please? Thanks.
    big J
    *****************this is Server.java ***************************
    package single;
    import java.io.*;
    import java.rmi.Naming;
    import java.rmi.RemoteException;
    import java.net.*;
    import java.rmi.*;
    public class Server
    extends Thread {
    public static final int SOCKETPORT = 5555;
    private String serverName;
    public Server() throws IOException {
    System.out.println("*** socket opened ***");
    serverName = new String("localhost");
    ServerSocket serverSocket = new ServerSocket(SOCKETPORT);
    Socket socket = serverSocket.accept();
    InputStream is = socket.getInputStream();
    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is));
    System.out.println(bufferedReader.readLine());
    OutputStream os = socket.getOutputStream();
    PrintWriter printWriter = new PrintWriter(new OutputStreamWriter(os), true);
    printWriter.println("from server");
    os.close();
    is.close();
    socket.close();
    System.out.println("*** socket closed ***");
    public void runServer() {
    System.out.println("*** start of run():RMI ***");
    System.setSecurityManager(new SecurityManager());
    try {
    RMIInterfaceImpl rMIInterfaceImpl = new RMIInterfaceImpl();
    Naming.bind("//" + serverName + ":9999/RMIInterface", rMIInterfaceImpl);
    catch (RemoteException ex) {
    catch (MalformedURLException ex) {
    catch (AlreadyBoundException ex) {
    System.out.println("*** end of run():RMI ***");
    public static void main(String args[]) throws Exception {
    Server server = new Server();
    server.runServer();
    ******************this is Client.java **************************
    package single;
    import java.io.*;
    import java.net.*;
    import java.rmi.Naming;
    public class Client {
    private String serverName;
    private final static int SOCKETPORT = 5555;
    public Client() throws IOException {
    serverName = new String("localhost");
    Socket socket = new Socket(serverName, SOCKETPORT);
    OutputStream os = socket.getOutputStream();
    PrintWriter printWriter=new PrintWriter(os, true);
    printWriter.println("from client");
    InputStream is = socket.getInputStream();
    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is));
    System.out.println(bufferedReader.readLine());
    is.close();
    os.close();
    socket.close();
    public void runClient() throws Exception {
    System.out.println("*** start of runClient():RMI ***");
    System.setSecurityManager(new SecurityManager());
    RMIInterface rMIInterfaceImpl = (RMIInterface) Naming.lookup(
    "//" + serverName + ":9999/RMIInterface");
    String str = rMIInterfaceImpl.print();
    System.out.println(str);
    rMIInterfaceImpl.serverSide();
    System.out.println("*** end of runClient():RMI ***");
    public static void main(String args[]) throws Exception {
    Client client = new Client();
    client.runClient();
    ***************** this is RMIInterface.java ***********************
    package single;
    import java.rmi.Remote;
    import java.rmi.RemoteException;
    interface RMIInterface
    extends Remote {
    String print() throws RemoteException;
    void serverSide() throws RemoteException;
    ********************* this is RMIInterfaceImpl.java ***************
    package single;
    import java.rmi.RemoteException;
    import java.rmi.server.UnicastRemoteObject;
    public class RMIInterfaceImpl
    extends UnicastRemoteObject
    implements RMIInterface {
    public RMIInterfaceImpl() throws RemoteException {}
    public String print() {
    return new String("hello world");
    public void serverSide(){
    System.out.println("this should appear in serverside");

    I think you have a timing problem between your client and server. As soon as your client and server programs have finished their socket communication, they will both do their "runServer"/"runClient" methods. If the client attempts to lookup the server before the server has registered itself via Naming.bind(), I would expect that's why you're getting a NotBoundException in the client.
    You probably wouldn't use the design of your test client/server for something significant, but a quick and dirty way to make this work might be to have the client call Thread.sleep() for a few seconds before trying to do the lookup.

  • Difference Between JMS and RMI

    Difference Between JMS and RMI in J2EE Technologies

    STFW
    JMS - http://www.google.co.za/search?hl=en&q=what+is+jms&meta=
    RMI - http://www.google.co.za/search?hl=en&q=what+is+rmi&meta=

  • Differnce between RPC and RMI

    Hello,
    Can anyone please tell me in detail the difference between RPC and RMI? If possible can you pls give examples?
    Thanks in advance.
    KiranJyot

    Thank you for the reply.
    Yes, I did google about this. But, it was not clear to me. I did ATM application using both RPC and RMI. Even though, it worked fine and did not lose points in my assignments, unfortunately the concepts were not clear.
    Can you please explain me what does it meant by - there is objects involved in RMI. In RPC, invoking functions is done through a proxy function. It will be great if you can explain it using ATM application.
    Regards,
    KiranJyothi

  • Difference between socket and http in opera mini

    Sir,
                     can any one say in simple language, what is the difference between socket and http connection. Is http connection possible in opera mini? Which is best suited for economy in use and fee
    Solved!
    Go to Solution.

    First thing to do is to make your phone open the web pages. I don't think the phone has low speeds.
    First
    ask your customer care for correct access point.
    1.
    Copy the access point name you received from custome care to-
    Settings-Connectivity-Packet data-Packet data setting,
    edit active access point.
    Give any name to active access point and activate it.
    Now goto settings- configurations - personal config.- add new- web, give any name to web and press back twice.
    Now again add new access point in personal configurations, give any account name to this access point.
    Copy the access point name which you got from ccare to bearer settings- packet data access pt.
    Press back three times and activate this access point.
    Now in default config. Settings activate personal config.
    Now all apps which need internet connection like
    opera mini should work fine.
    2.
    Saved pages of Opera mini 4.x won't open with opera mini 7.x version.
    Saved pages are stored with an extension .obml.
    Connect memory card to your pc using a card reader,
    you can find them by enabling hidden folders and searching .obml.
    Now right click on any obml file of search results and click open file location or move them to any folder you like and
    note down the files location.
    Now goto saved pages of your opera mini, manage, set folder. Set the folder location to where .obml files are stored
    Now your old saved pages can be opened.
    Hope this helps.
    -------------------If this post helped you, click on accept as solution.------------------
    -----------------------------Appreciate by clicking on white star.----------------------------

  • Choice Between IDOC and ABAP Proxy

    Hello All,
    We are building a Bi Directional Interface for Business partners between a third Party ERP, XI and SAP CRM.
    We are looking for some advise on the best way to go forward between the two options below:
    a) Do an ABAP Proxy Call on Fn Module CRMXIF_PARTNER_SAVE  from XI
    b) Create and IDOC in CRM
       ( Message Type CRMXIF_PARTNER_SAVE_M )
    Not being an XI consultant, my understanding is as follows
    Option A  : Gives me the flexibility to format my response in the manner we like. But this is a synchronous call. Also this is a generated RFC. So changes in the XIF layer of CRM could be an issue.
    Option B : Response can be achieved only through the ALE Audit Functionality, which has a predefined message structure. For Eg: If I wanted to send the response in the same format as the incoming message with an added segment for the error, this is not possible. Ofcourse, I get all the functionalities of monitoring and Handling IDOCs in this option.
    Any thoughts on the advantages and disadvantages of each option would be greatly appreciated.
    Thanks
    Anoop

    Anoop,
    I probably should have mentioned in the BLOG, that IDOC is good if its a standard IDOC, so that you don't have under go the pain doing the modifications for the custom one.
    In your case, PROXY might make more sense as you are saying that you have to do some custom processing as well. So, you can call the BAPI / Function for the standard processing and then do the custom processing in your Proxy code. And more over, if you have want to have a Synch interface, then you cannot use IDOC.
    So, the options in this case boil down to PROXY / RFC.
    PROXY will definitely have the advantage as its going to bypass the adapter engine and directly interact with the Integration server. And moreover, even if you already have a RFC, you can always call that inside your PROXY. However, the only flip side here compared to IDOC, is that you will have to create all your IR objects manually.
    Hope this helps you in making your decision.
    regards,
    Ravi
    Note : Please mark the helpful answers.

  • OS should allow choice between "deep" and "light" sleep (battery life)

    It's clear that Apple needs to fix the OS for the ipod touch so that the user can choose between one of two sleep modes. A "deep" sleep mode would be similar to sleep in pre- OS 4.1: WIFI would be automatically turned off to preserve battery. A "light" sleep mode would be similar to the sleep mode in the current OS 4.1 and would not shut WIFI off (but thereby quickly draining the battery).

    you might want to let Apple know via _*iPod Touch Feedback*_.
    JGG

  • Choice between T540p and T440p

    Hello all,
    I am new in this forum, so I am very excited to start.
    I am planning to buy either the T440p or T540p and I need to consult with you guys in order to make a good choice
    My needs are for a lightweight business laptop which features very good display/keyboard, has a very good battery performence and has a good three years international guarenty. Also, the price matters to me very much.
    Unfortunately, the the T440p is not offered with such warenty - only 1 year, and no IPS displat. However, other specs are what I need. The T540p has the 3 year warenty but is much havier and its batery will not last as the T440p.
    When I looked at the Lenovo site the picture becomes more complecated. The T440p is much more expensive compared to the T540p - more than $1,000 compared to $649, with more or less the same specs.
    So what should I do? I would pay the extra money for the T440p if it had the same warenty, but it is not available in Lenovo website. Just imagining carrying a 5.5lbs piece of mettal compared to the 4.7lbs' T440p (which is not a feather by itself) gives me an instant backpain...
    Thanks again,
    Uzi

    I'm not sure if either the T440p or the T540p is really considered lightweight. Maybe the T440s? Or X240s?
    W520: i7-2720QM, Q2000M at 1080/688/1376, 21GB RAM, 500GB + 750GB HDD, FHD screen
    X61T: L7500, 3GB RAM, 500GB HDD, XGA screen, Ultrabase
    Y3P: 5Y70, 8GB RAM, 256GB SSD, QHD+ screen

  • Choice between 8520 and 9300

    Hi, I'm in a bit of a dilemma, I would like to buy a BB but dont know which model to take, either the 9300 or the 8520. I have read through the differences between the 2 handsets and more or less the 9300 is better on paper.
    The provider is offering me the BB 9300 for 190 pounds (I'm just converting this into pounds) MORE than the 8520.
    My question is that,  is the 9300 a 190 pounds more better than the 8520?
    Thank you

    Hi and welcome
    Good thinking to check first. Thanks for converting into £ but this is multi-national so no need. Now as you have done I will explain about here in the UK.
    I'm guessing you are in the US and it seems to me you guys pay a fortune for devices and still have to buy carrier time.
    In the UK, at present, if you sign up for an 18 month carrier contract which will cost around £10 per month inc 500Mb data you get the 8520 FREE, nada, zip. And you get 12 months carrier warranty on the device as well. Maybe there are similar deals around you?
    The 8520 does not have GPS functionality and this makes it cumbersome for applications that rely on location settings such as FB Places and many others.
    The 8520 is unlikely to receive the latest software  - OS 6 due to limitations of the memory/processor. OS 6 is available for the 9300 and will probably come pre-loaded. There's nothing wrong with OS 5 but it cannot be upgraded on the 8520.
    Whichever you choose, make sure you have a data plan; without data you seriously limit the functionality of any BB and don't worry about extra data costs unless you have no Wi-Fi at home and want to be downloading music/video constantly. Last month, I used 2.6Mb of my 500Mb allowance.
    Good luck and hope to see you on here regularly.
    Blackberry Best Advice - Back-up weekly
    If I have helped you please check the "Kudos" star on the right >>>>

  • Choice between BI and CRM/SRM-Technofunctional.

    Hi all,
    Please tell me marketwise and onsitewise which one is better between Netweaver-BI
    and
    CRM/SRM functional-ABAP  (i.e. technofunctional with higher modules)as i am an ABAPer .
    Thanks.

    llll

  • Design choice between ArrayList and LinkedList

    Can someone clarify me which is better suited (efficient) for use?
    It appears to me that both can be used very much interchangeably at least from functionality point of view. :(

    Using the following code (and I'm sure someone will come nitpicking about it) I get the (expected, at least by me from prior experience) result that iteration over a LinkedList is about twice as fast as iteration over an ArrayList, but lookup operations on an ArrayList are substantially faster:
    package jtw.test;
    import java.util.*;
    public class SpeedTest {
        public static void main(String... args) throws Exception {
            List<Integer> linked = new LinkedList<Integer>();
            List<Integer> arr = new ArrayList<Integer>();
            for (int i = 0; i < 1e3; i++) {
                linked.add(i);
                arr.add(i);
            long r = 0;
            Date startLinked = new Date();
            for (int i = 0; i < 1e3; i++) {
                for (Integer q: linked) {
                     r += q;
            Date stopLinked = new Date();
            System.out.println("Total: " + r);
            r = 0;
            Date startArr = new Date();
            for (int i = 0; i < 1e3; i++) {
                for (Integer q: arr) {
                     r += q;
            Date stopArr = new Date();
            System.out.println("Total: " + r);
            System.out.println("LinkedList iteration: " + startLinked + " to " + stopLinked + " took " + (stopLinked.getTime() - startLinked.getTime()));
            System.out.println(" ArrayList iteration: " + startArr + " to " + stopArr + " took " + (stopArr.getTime() - startArr.getTime()));
             r = 0;
            startLinked = new Date();
            for (int i = 0; i < 1e3; i++) {
                for (int j = 999; j >= 0; j--) {
                     r += linked.get(j);
            stopLinked = new Date();
            System.out.println("Total: " + r);
            r = 0;
            startArr = new Date();
            for (int i = 0; i < 1e3; i++) {
                for (int j = 999; j >= 0; j--) {
                     r += arr.get(j);
            stopArr = new Date();
            System.out.println("Total: " + r);
            System.out.println("LinkedList lookup: " + startLinked + " to " + stopLinked + " took " + (stopLinked.getTime() - startLinked.getTime()));
            System.out.println(" ArrayList lookup: " + startArr + " to " + stopArr + " took " + (stopArr.getTime() - startArr.getTime()));
    }Gets the result:
    D:\jdk1.6.0_05\bin\java -Didea.launcher.port=7540 "-Didea.launcher.bin.path=C:\Program Files\JetBrains\IntelliJ IDEA 8.0.1\bin" -Dfile.encoding=windows-1252 -classpath "D:\jdk1.6.0_05\jre\lib\charsets.jar;D:\jdk1.6.0_05\jre\lib\deploy.jar;D:\jdk1.6.0_05\jre\lib\javaws.jar;D:\jdk1.6.0_05\jre\lib\jce.jar;D:\jdk1.6.0_05\jre\lib\jsse.jar;D:\jdk1.6.0_05\jre\lib\management-agent.jar;D:\jdk1.6.0_05\jre\lib\plugin.jar;D:\jdk1.6.0_05\jre\lib\resources.jar;D:\jdk1.6.0_05\jre\lib\rt.jar;D:\jdk1.6.0_05\jre\lib\ext\dnsns.jar;D:\jdk1.6.0_05\jre\lib\ext\localedata.jar;D:\jdk1.6.0_05\jre\lib\ext\sunjce_provider.jar;D:\jdk1.6.0_05\jre\lib\ext\sunmscapi.jar;D:\jdk1.6.0_05\jre\lib\ext\sunpkcs11.jar;F:\dev\Euler\out\production\Euler;C:\Program Files\JetBrains\IntelliJ IDEA 8.0.1\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain jtw.test.SpeedTest
    Total: 499500000
    Total: 499500000
    LinkedList iteration: Wed Jan 21 07:32:41 CET 2009 to Wed Jan 21 07:32:41 CET 2009 took 30
    ArrayList iteration: Wed Jan 21 07:32:41 CET 2009 to Wed Jan 21 07:32:41 CET 2009 took 53
    Total: 499500000
    Total: 499500000
    LinkedList lookup: Wed Jan 21 07:32:41 CET 2009 to Wed Jan 21 07:32:42 CET 2009 took 424
    ArrayList lookup: Wed Jan 21 07:32:42 CET 2009 to Wed Jan 21 07:32:42 CET 2009 took 22
    Process finished with exit code 0Given the internal representation of the datatypes, this is to be expected.

  • Choice between VISA and GPIB drivers

    I have a waveform generator with a GPIB port. I would like to build my own VIs. Can someone suggest which driver (VISA or GPIB or IVI) would be preferable and what are the differences in terms of ease among these drivers?

    Hello Craig,
    I have an Agilent 33220A frequency generator for which I have already found drivers from the Instrument Driver Network. I am a beginner in LABVIEW and am in the process of improving my skills in communicating with instruments. So far, I have been communicating with other instruments using VISA and a serial port.
    While going through LABVIEW HELP, I realized that VISA, GPIB and IVI drivers can be used for communicating with a GPIB instrument port. This being the case, I would like to know which of the above-mentioned drivers is preferable?
    Thanks
    Ram

  • Choice between xquery and parsing methods

    I want to read from an xml source file. I have been working with parse techniques (JAXP )and Marshal/Unmarshal techniques(JAXB).
    Recently i came to know that we can query an xml document using xquery and
    xpath methods.
    Is the second method advantageous than the first one in terms of time and memory constraints ?

    Yes, xquery and xpath are always easy to work than parsing on your own.
    It provides already written methods for u, which u need not to write on your own to fetch the data.
    Hope this will help u.
    ......yogesh

  • Choice between syncronous and asyncrous BDC

    HI Experts,
    can you kindly guide when one shall go for asynchronous BDC and when for syncronous BDC?
    Thanks.

    Hi Sanjay,
    There are several answers to this question already in the forum - just do a search!

  • Choice between JSP and Servlet

    I am new to JSP and Servlet. I know JSP container will convert JSP to servlet
    eventually. But in application development's standpoint, anything can be
    done in servlet can also be done in JSP? Some people told me we can
    use the combination of both in one application.
    My question is in what situation we use JSP alone, servlet alone, or
    combination of both??
    Please advise. Thanks!!

    Use a combination of both.
    Your Web application should have a single servlet that all HTTP requests are POSTed to. All the servlet does is act like a traffic cop: it figures out what the request is, delegates to other objects that do the work, and forward the result to the next JSP, whatever that is. It's called a front controller servlet.
    The JSPs should just be pure dynamic presentation. Everything displayed in the pages should have been generated by the servlet and its helper classes. No database queries, etc. Your JSPs will be a lot better off if you learn JSTL and eliminate all scriptlet code.
    Check out frameworks like Struts.

Maybe you are looking for

  • Customer balance confirmation

    Hi all, I have F.17 standard transaction code assigned to a Z program in SAP 6.0 which is very strange to me. All the company codes are assigned to the standard program SAPF130D. How can I run the program, with what transaction? I cannot assign a new

  • Illustrator crashes after moving an object

    On the first day everything was working fine, but now I have a problem moving an object. Every time I am moving an object with the cursor the illustrator crashes. HELP!!!! (a friend told me it's graphic card problem, but still I can't find what cause

  • Backup your contacts first, before joining any cloud

    This is not a question.  It is a reminder.  Be sure to backup your contacts on any device before joining any other source of contacts.  You can backup your Mac address book through the menu, your ipad/iphone are backed-up through itunes and there are

  • I need some help with apex_item.date_popup2

    Hi everyone, I just recently found out about apex_item.date_popup2 and I'm having some trouble working with it. I'm not sure how to associate it with a attribute I have already. My select for the popup so far is: apex_item.date_popup2(30, sysdate, 'D

  • Items detected on your pc require further analysis

    Hello, since last week FEP is displaying on our desktop a alert that says: "Items detected on your pc require further analysis. By sending the files listed below, you can help Microsoft analysts determine whether these systems are malicious." the app