I am having difficulties understanding the difference between network mode and non-network mode terms as used when dealing with client server applications in java.
I know how to develop simple client server apps. For example I can create a client application and server application. These applications can connect to through sockets and send and receive data. I however get confused when people talk about running a server and client in standalone mode, where both the client and server use the same instance of a JVM without loop back networking involved. I have seen this happening with the java derby database.
So my main question is how do you take code that was using sockets to communicate and convert it to use the so called "standalone mode" where the client and server run as one application? I will appreciate any comments that point me to the right material.
In the so-called network mode you have to connect to a remote server, as you describe, typically through a socket and so your client asks the server to do certain task, the server carries out the task and responds to the client.
In this mode, it is customary that the client and the server will be different nodes, that is different machines, running independently.
But what if you wanted to run you client and your server in the same machine? Even in the same virtual machine? Would it make sense to go through a socket to ask your server to do something?
That would be like using Skype to chat with a friend sat right by your side, to simply ask him to go have lunch.
So, ideally, in these cases, you should be able to run your application in non-network mode. That is, instead of going through a socket, you access your sever object directly and ask it to do something for you. Since your server object is located in the same virtual machine as your client.
Evidently, for you to be able to do this, you need a good design that exposes your server functionality through an interface, and your application uses this interface to interact with the server. When you are running in network mode, you use an implementation of this server interface that uses a socket (or RMI or whatever you do for network communication). When you are in non-network mode, you get an implementation of the server object itself.
Related
I'm developing a Desktop LAN base java server and client application
where a Client must login and also to pass some data to server.
assuming i have 10 clients that inserting record simultaneously to server.
which is the best approach in this kind of situation, should I use RMI for login and record insertion? or Sockets?
if sockets please provide a key idea for me to start with.
key points to consider
-Multithreading
-able to send back data on client
If you want to connect your server via internet (and/or firewalls) it is probably a hassle to do this with plain RMI. In the past I have used Java Simon for such tasks which is very easy to implement. However if you plan to support other clients than Java clients, then you should have a look at Apache Thrift or Google Protocoll Buffers
I would like to know if with RMI a server can remotely invoke a method from any of his clients, or just the clients can do this with their server.
Regardless of any implications of such a design decision, it is possible to use RMI between two JVMs that are accessible through the network. This means that if the server can access its clients through the network, and the clients have a JVM available and can act as RMI servers, then it is possible to make a client or each of the clients an RMI server and have the "server" communicate with each one of them.
Assuming the server is an application server i advise you to use the Java Messaging Service (JMS) to allow the server communicate with the client systems.
Yes, firewalls permitting. The client has to export its callbacks as remote objects and supply them to the server, typically via some registerCallback() API. Then the server just calls the methods.
However firewalls to the Internet typically don't permit callbacks, and if they do there may be issues with port numbers: you will probably need the clients to export their remote objects on a specific port which is opened in the firewall, typically 1099.
Besides the solution provided by melc, it is also possible to achieve a full duplex communication between the client and server by using WebSockets. They are now part of the Java EE 7 specification, you can read something more about them here: http://docs.oracle.com/javaee/7/tutorial/doc/websocket.htm. There are also other solutions, like Comet, or JMS (which is used like webosckets in RichFaces).
I am developing system, that consists of client (written in JavaFX) and server. Now I am going to implement server. Users will download clients. Clients will communicate with server (only one server and many clients). Server will communicate with data base and send results. Server will support authentication and different requests (not http of course). Is it a good idea to implement server with Java RMI? If no, could you advice me any good idea about server realisation.
Thanks a lot for future questions!
RMI is bit kind of traditional but still powerful to me ,it has some draw back . But, despite the RMI there is also a chance for you to use java sockets class ? just like a client -server application ...
i am developing an android application in which the server side execution is done using a simple java udp program.i want to know how i can host this application because i need a static ip server to run the java program.can i run my java program in a server.is it possible if yes how?
You'll have to write a listener in some language (PHP, Java, Etc.). As for a static ip address, you can also look at a dynamic ip redirection service like no-ip;
http://www.no-ip.com/services/managed_dns/free_dynamic_dns.html
You can use a personal machine thats always online, or you can try to use a shared hosting plan that allows you to have a listening port open. A web service will likely be easier to work with than having some custom UDP/TCP connection.
OK, I'm new to server-client applications, and i need some basic information, so forgive me if my question is not clear...
I want to make a chat application that would function like this:
Client A sends information to server, server sends the same information to client B, and vice versa... Think of it as of a simple chat program.
All communication is done through sockets, so i would have a server socket application, and a client socket application... I want my client application to be on my PCs and server application to be on a remote server ( it would be hosted on some free hosting websites).
My question is how do I start that server application on that remote server?
Thanks in advance!
If you are just trying to make a chat client, I don't think you would need an intermediate server. Just connect two machines using server and client sockets
SERVER:
ServerSocketChannel serverSocket;
serverSocket = ServerSocketChannel.open();
serverSocket.socket().bind()
serverSocket.socket().accept()
CLIENT:
SocketChannel clientSocket = SocketChannel.open();
clientSocket.connect();
Of course you would have to use the bind and connect functions properly. Read up on their API's
The remote server can be started manually. (If you do not have access to remote server or if you are hosting your server on some third party infrastructure, then they might have a way to do it.)
To be able to start it remotely via some program, you again need a server on the remote machine that listens to this kind of requests.
Usually, you want an application that is running all the time at your hosting provider (like a web server or perhaps inetd) to start (or embed) your application. The details will be determined by what your hosting provider provides.
If you're using plain sockets, you should look for some remote server with SSH login. You're able to start your application on the shell then, sth like:
java -jar yourapp.jar
Free hosting websites are rather targeting customers that want to host their website. In my opinion that is not the best choice for hosting a socket application.
For developing purposes, I'd stick with the local machine for the beginning. Running/testing server/client connections on the same machine is much easier as you don't have to work on two different machines, copy code, etc.
This tutorial is relatively short, but fully covers basics of Java networking. And it is right about simple chat.