Java RMI stand-alone applications
Is it possible to create a Server – Client Java application using RMI that can run just by running the server and the client (with servers IP), without any change on any environment variable, or installation of any other program?
As far as I know, to make an RMI compo (Server – Client) to work, you need:
server application
client application
protocol file(s) (implementations) common for both
but the location of the server must be accessible by the client. Is there a way that java can make it accessible without any help?
Is it possible to create a Server – Client Java application using RMI that can run just by running the server and the client (with servers IP), without any change on any environment variable, or installation of any other program?
RMI doesn't have environment variables or separate programs.
As far as I know, to make an RMI compo (Server – Client) to work, you need: server application client application protocol file(s) (implementations) common for both
No you don't. There is no such thing. You just need the relevant .class files in each place. I can't imagine where you are getting this misinformation from.
but the location of the server must be accessible by the client. Is there a way that java can make it accessible without any help?
No. Accessibility is a property of firewalls. If you could change that from the client there wouldn't be any point in having them in the first place.
Related
We are developing a client-server application with Java RMI and, for testing, we will use a computer both as client and as server. So both the client and the server applications must call rmiregistry on the same machine, but they are two different JVMs obviously. How can we do that? We hoped that it was necessary only to give different ports to LocateRegistry but we get NotBoundException...
What is the correct way?
You can run as many as you like, but why? You don't need to. Have the server start its own Registry via LocateRegistry.createRegistry(), and have the client lookup that one. You seem to think the client needs its own Registry, which isn't correct.
If you got a NotBoundException clearly either the service wasn't bound at all in any registry, or you looked up the wrong one.
RMI Registry is a server which maintains a registry of services.
So your server should connect to the RMI registry and register itself in it, while client should connect to RMI registry and look up your server
So you need to run a single RMI Registry on your machine.
It seems that you're getting the NotBoundException cause you have two of them
I'm really new to Java RMI, and I don't quite understand what it actually does. When a remote method is called, is the method executed on the server, or the client? In other words does RMI utilize the servers resources or is it simply used for access to remote classes and methods which will run client side?
Java RMI (Remote Method Invocation) uses client side "stubs" to connect to server side implementation and the real work is done on the Server side.
I have created one sample chat application. In that chat application, I used JApplet and front end.
Till now I was testing my application in my desktop. It is working fine. Now I want to deploy my application over any webserver.
Now I have a few questions. Currently I am using Server socket as 8989 in my chatserver. When I was testing the application in my desktop, I used to start the server as stand alone.
What are the steps I have to follow when I deploy the application over tomcat or any other web server? Which port the client will listen?
How do I start my chat server? I am new to the socket concepts.
when you say you are hosting on the webserver, i believe that its an servlet/jsp based application , which will listen to your requests , in that case the listener will be invoked at the webserver default port either 80 / 8080 (being default). In case you want to change or check , you can go to the TOMCAT_INSTALLATION_DIR/conf/server.xml and check for tag containing the port number for weblistener, and change it to whatever value you feel like.
if thats not the case and you have your own thread which opens a socket for you , you really dont need a webserver, all you need is a host machine which will start the socket listener ( your custom) and then it will listen at the port that you have configured it to be at.
As far as I got it, you're having standalone application as a server, where you handle connections to particular port.
I think there is some confusion that should be clarified.
The very basic question is:
Why do you need your chat server to be running on the web server?
This should be clear to you prio to any later steps.
As web server is there basically to handle HTTP/S requests and that's not your case, as far as I got it. As you're probably running socket TCP/UDP communication.
For the web server however your client applet implemnentation could benefit of. If it would be referrend on a simple html page (deployed inside war) it could be simply redistributable to clients via url call in a web browser.
Maybe I'd preffer to use HTTP + JSON commununication, where you could benefit from web server usage (also on the server side) and would not need any other ports than standard ones.
Not sure if it still makes sence to answer your questions as it might be irrelevant for you, but let's see.
Answers to your questions:
Basically you need war archive (rather than jar one), as that's the one accepted by web servers. once you create it (you need to follow the correct folder/file structure inside) your app could be deployed to web server.
Which port the client will listen? Basically server is the listener here => no client port listening here.
This depends on your communication implementation decision. If still sticking with TCP/UDP one, I don't think web server would be beneficial here.
I have two servers, one that runs my program written in Java (Server A) and one that stores a graph (Server B) that must be continuously accessed by Server A. To access Server B you must ssh with a username and password using Server B's IP address.
As of now I have failed to find a method to continuously access a directory on a different server and I am wondering if anyone knows a method that lets me do this (or if it is not possible, if there is a workaround).
I have looked into SSH libraries, but they all seem to only give you access to the directory for a brief amount of time. I need continuos access because I write and read from the graph on Server B all the time.
I basically want to make a proxy directory on Server A that actually refers/links to the directory on Server B:
graphDb = new EmbeddedGraphDatabase("/192.168.1.**/media/graphDB");
Any help would be great.
Probably unrelated option:
If client and server are Linux machines, you can use rsync to synchronize files between them. In that way you have a copy of the files on server A. The rsync command could be executed from the Java program or periodically from a cronjob on server A.
You could write your own client/server service, so that the server service provide you with the means to send data over the network to. It tends to be a lot of work though.
You could write your self a "heart beat" service on the client that tests the SSH connection and reestablishes it if it closes
You could "test" the ssh connection before you writing/reading from the connection
You could do as AlperAkture suggests (and mount the directory as a remote drive)
I have a client/server applciation that communicates through JNDI/RMI/IIOP using, on client side, some Glassfish client code (NOT packaged as a Glassfish client) and on server side a Glassfish instance.
I have some Glassfish multimode scripts that I use to make sure the domains I create on any machines are totally identical and correctly configured.
Using that script on local network, I have already made sure I could access a remote Glassfish server instance from client code on my machine (that was quite a reasonable guess, however I tend to test all things I'm not totally sure of).
Next step is to have that client/server application working over (I should instead say "through") internet : with my client code in my company LAN (in other words on my machine) and my server code on an Amazon VM running my Glassfish server. For some reasons, the remote Glassfish is running on a Windows VM.
Obviously (as I ask that question, you can safely guess the through internet test is NOT working. And you're right.
So, to have more guesses, I started SmartSniffer both on my machine and on server.
On my machine, I can only see one TCP packet going to that server instance (and nothing coming back).
On server instance, I can see one packet entering (the client query) and one packet exiting (the server answer). That server answer looks like this :
[4/4/2012 11:47:13 AM:917]
GIOP.......(................NameService....._is_a...................NEO................ª.......(IDL:omg.org/SendingContext/CodeBase:1.0............n........172.27.63.145.Ô2....¯«Ë........e...........................
...................
... ...........&...............(IDL:omg.org/CosNaming/NamingContext:1.0.
That 172.27.63.145 address is my IP in local network.
[4/4/2012 11:47:13 AM:917]
GIOP.......2............NEO................0.......(IDL:omg.org/SendingContext/CodeBase:1.0............ô........46.137.114.###.'5....¯«Ë........d...........................
...................
... ...........&...........!...|...............$...
...f............10.241.42.###.'6.#........g..............g........default...................g...............+IDL:omg.org/CosNaming/NamingContextExt:1.0.............¢........10.241.42.208.'5...M¯«Ë....
...d... S1AS-ORB............RootPOA....
TNameService............................... ...................
... ...........&......
That 46.137.114.### is external one of my Amazon VM, and 10.241.42.### is its internal IP in amazon magical virtual server.
So it seems server is answering, no ?
But that answer never finds its way to my machine in my network.
So ... how can I check where it get lost ? Seems likepacket sniffer has done its job, but what can I do now ?
NOTE This question is a clarification of "How to Connect a glassfish client to glassfish server over NATs?"
Perhaps stupid question, but is your Amazon EC2 instance is configured with all required ports open for your communication protocol to work? You could see configured open ports in security group your instance assigned to in AWS console, under EC2->Security Groups.