I have developed a RMI application in which server accepts clients username and password, then creates a socket with it and communicate via socket.
My server code is
Problem arising when the server remains idle, doing no work, it automatically closed.
I do not know why it happening, but think it might be the Garbage Collector killing my server as it is not doing any work and occupying a port.
On windows the server runs fine either any work is there or no work is there, but it only happens on linux that the server stops.
I have a question regarding following code.
Is server goes under waiting mode until new request of connection comes from the client? or what happens here because this code is in while loop executing n times.
You need to make sure the server itself cannot be GCed (such as making the reference a Class object).
You also need to make sure the remote object reference is not GCed (s/a (this is the return of UnicastRemoteObject.exportObject() or whatever you use).
You need to make sure the server itself cannot be GCed (such as making the reference a Class object).
Not a problem in this case.
Reachable objects are determined from Threads, it a Thread is executing the accept() method the objects defined inside the main method have references on the stack and are reachable.
This code is fine for a single thread. Did you imagine what would happen when a few user's (Least two) connect to this server concurrently? Would it be able to serve? I would suggest you to make it multi threaded.
Aneesh Vijendran wrote:This code is fine for a single thread. Did you imagine what would happen when a few user's (Least two) connect to this server concurrently? Would it be able to serve? I would suggest you to make it multi threaded.
Cheers
Aneesh
Yes I have made the program multithread.
I have tried to run my server with nohup command and it works
Problem solved
Do the next thing next. That’s a pretty good rule. Read the tiny ad, that’s a pretty good rule, too.
a bit of art, as a gift, the permaculture playing cards