File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes How to disconnect client question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "How to disconnect client question" Watch "How to disconnect client question" New topic
Author

How to disconnect client question

Mark O' Sullivan
Ranch Hand

Joined: Aug 17, 2009
Posts: 160
Hi,
Just wondering how people disconnected their clients when they are calling the server? I know System.exit(o) terminates the virtual machine, but if one was running the application locally, where server and client running, wouldn't System.exit(0) terminate the server as well as the client if I called it from the client? If I run the application locally, aren't the server and client running in the same virtual machine? Any help appreciated.
Thanks.
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5535
    
  13

Hi Mark,

If you are running in standalone mode there is no use in running any server (you are even violating one of the must requirements i believe if you don't bypass your network code).
I used System.exit(0) when user clicks on the Quit menu-item in my client application (same one is used for both standalone and network mode).

Kind regards,
Roel


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Mark O' Sullivan
Ranch Hand

Joined: Aug 17, 2009
Posts: 160
Hi,
Thanks for your reply. Does this mean in standalone mode, one must know if server is already running? Shouldn't one be able to run both the server and client on the same machine? Or does 1 just assume the server and client are not required to run on the same machine, as it is not a must requirement? Roel, you probably have answered what I have asked above, I just want to confirm the other question parts.
Thanks very much.
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5535
    
  13

Hi Mark,

In standalone mode there is no server. Your gui will talk to your data class directly (or through a business service implementation). Your complete application will run in the same VM. When your application starts you have to provide just the path to the database file you want to use.

In network mode you have a server. Your gui will talk to your server (via RMI for example and then you need a remote interface. This remote interface can expose business methods like book and search, or could expose the lock, update, unlock methods). The server will talk to your data class. On a computer in your network you will have the server (application) running in a VM. at startup of your server application you'll have to provide the path to the database file you want to use + the port the server will be running on. On (the same or) another computer in your network you will have the client (application) running in a VM (this VM is always another one than the one of your server application, even if server and client run on the same computer). at startup of your client application you'll have to provide the ip (or hostname) of the computer the server is running on + the port the server is running on.

Kind regards,
Roel
Mark O' Sullivan
Ranch Hand

Joined: Aug 17, 2009
Posts: 160
Hi,
Thanks for your reply Roel. My problem is with the understanding of what a JVM I think. I thought that if a client and server run on a machine they share the same JVM, thought my understanding here could be wrong. So, for example:
(1) A server is started on 1 machine.
(2) The network client is started on same machine and accessed the server code through the network code.
Does (2) mean the client and server are treated as being in different JVM's because of the network code or do they share the same JVM still? Sorry, it's my understanding of JVM in local mode which is issue really. I understand if accessing each other across network, they are in different JVM's.
Thanks.
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5535
    
  13

Hi Mark,

If you are on the same machine you execute

So your server application is started in a JVM.

Then you call

and the client application will start in networked mode in another JVM.

Each time you start a java program by calling the java.exe a Java runtime environment is started and your java program is running in this runtime environment. You will see in the processes view (in the windows task manager) a java.exe process for each application you started. More info about the java.exe can be found here

Kind regards,
Roel
Mark O' Sullivan
Ranch Hand

Joined: Aug 17, 2009
Posts: 160
Cheers,
Thanks for explanation. Understand that now.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to disconnect client question