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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top