File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Distributed Java and the fly likes Java RMI Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "Java RMI Question" Watch "Java RMI Question" New topic
Author

Java RMI Question

Carlos Valderrama
Greenhorn

Joined: Feb 20, 2013
Posts: 14

Hello folks it's me again! I hope you're all right,

I'm developing a small client-server java RMI application,

In wich I want the user of the server side to start the server and fill the value of a jTextfield. then that value will be taken and sent to the clients when they remotely invoke the method.

Ok, here's the thing:

If i pre-fill the Jtextfield then start the server->and run the client the value gets correctly returned

BUT ( there's always a but)

if I run the server and change the value of the jtextField that new value will never be get by the client,

My question is:

is it possible to return the value the way i'm thinking??


Any help would be really appreciated.






K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2503
    
    8

Carlos Valderrama wrote:
In wich I want the user of the server side to start the server and fill the value of a jTextfield. then that value will be taken and sent to the clients when they remotely invoke the method.


From the client point of view, they just need the IP or hostname and the port to connect. Nothing else.

What is the JTextField for? If it's for a DB file or similar, yes but you not need to enter the IP per se. Maybe the port (default 1099 if I remember correctly).

Assume you can "sent this JTextfield's value" to the client, you can't control when the client will connect. It's like send some value to outer space.


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5 OCPBCD5
Carlos Valderrama
Greenhorn

Joined: Feb 20, 2013
Posts: 14

Thank you for your reply K. Tsang,

Let me try to explain myself a litte bit more clearly:

Here is the code of the server side, I need to type and/or change the value of the jTextfield whenever I want , but that value doesn't get updated and sent to the clients, ( as i said the method seems to be working cause if i prefill the jtextfield before compilation the jtextfield value that string gets correctly sent to the clients)

public class Principal extends javax.swing.JFrame implements Sendpar {

/** Creates new form Principal */
public Principal() {
initComponents();
}
@Override
public String envPar() {
String u=jTextField1.getText();
return u;
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try {
Principal obj = new Principal();
Sendpar stub = (Sendpar) UnicastRemoteObject.exportObject(obj, 0);
// Bind the remote object's stub in the registry
Registry registry = LocateRegistry.getRegistry();
registry.bind("Sendpar", stub);
System.err.println("Server ready");

} catch (Exception e) {
System.err.println("Server exception: " + e.toString());
}

}


Any comment would be appreciated friend!


K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2503
    
    8

Thinking about it, this isn't a RMI problem. It's a Swing problem.

You basically have a JTextField get that. Want to change it whenever you want, click submit and voila the value sends to client.


Carlos Valderrama
Greenhorn

Joined: Feb 20, 2013
Posts: 14
K. tsang, i think again i didn't make myself clear..

I'll try one more time:

i have client application in wich i invoke a method thas has been implemented on the server,

such method on the server side needs to collect the data from a jtextfield any time a client request it.

The problem i'm facing is that the method on the server side doesn't "gets the updated data on the jtextfield".

Additionally i want you to know that if i start the server with a pre-filled text on the jtextfield the clients get to read it correctly.

But as i said, any update to that field won't be recognized by the client side.


I'm sorry it must be that my english isn't very good looking



Carlos Valderrama
Greenhorn

Joined: Feb 20, 2013
Posts: 14
brother I'm sorry i've unnecessarilly taken your time,

I was making a newbie mistake,

Principal obj = new Principal();
Sendpar stub = (Sendpar) UnicastRemoteObject.exportObject(obj, 0);


I was genrating a new object of the frame hence the new value would never be taken.


I'm so ashamed..





K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2503
    
    8

Nice to hear you figured it out. I honestly didn't realize that line was an issue in the first place.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java RMI Question