• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How can I return a value to server in java RMI?

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I have developed an application in Java RMI which returns factorial of a number to client. Also I set a limitation value in server side. Like during starting the server it can decide upto which limit it will let the client to do the factor. For example if the server set the value 10 than client can get the factorial value upto 10. If client input the value more than 10 it will get an error message. Now I want to return the factorial value to server class also. I know I am doing something wrong but I am not understanding what I am doing wrong. Following is my code.

Interface class - FacInt

Implement class - FacImpl

Server class - FacServer

Client class - FacClient

Here is my server and client input/output respectively.

Server



Client




I understand here FacImpl class returns the value before client connected. How can I do that after client connects?

 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Shihab Hazari wrote:Now I want to return the factorial value to server class also.



But the server calculates the factorial value. Surely you aren't asking for the server to return the factorial value to itself? So what exactly are you asking for?
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, now that I look at your code in that light, there are some problems with it. Servers are generally supposed to be stateless, but your FacImpl code isn't. The variable "j" is an instance variable which can change, and hence it's vulnerable to race conditions when two clients use that FacImpl instance at the same time. And the code seems to have a method which tries to return the last factorial computed, or something like that. (The method names don't make it clear what the methods are supposed to do, which is unhelpful.) I don't know why you would want that method, since it prevents the FacImpl instance from being stateless. And if you imagine a real-life application with a similar design, say "Compute Account Balance" and "Return Last Account Balance Computed", it could lead to security problems when you return Customer A's account to Customer B because it was the last one computed.

So I expect your question will go away if you start using the RMI server the way it was meant to be used, as a stateless server which strictly returns a result based on the data in the request and nothing else.
 
This will take every ounce of my mental strength! All for a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic