• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

Running a Java function from another Java program on different computer in a network  RSS feed

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am Completely blank on this, tried weeks searching for any possible similar case on the internet,and havent understood or found something that help.

so let say, I have a simple Java Program named Java1 on Computer A, this Java Program has a jButton that when Pressed, does this :

   

now I want to make a separate second simple java Program named Java2 with only a jButton, when I run this Java2 on another PC that is in the same LAN / WLAN network with the Computer A, when I press the jButton on the Java2 app it will do the same to the labelNum in the Java1 program ran on the Computer A as the jButton on Java1 app does.

I am completely have no idea on how to do this, hence I couldnt provide any piece of code.

 
Dave mann
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I posted this on the wrong section.

and as a note.

the labelNum has initial value in text = "0".
 
Sheriff
Posts: 5917
155
Chrome Eclipse IDE Java Postgres Database Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There may be other ways to do this, but I would use sockets.  Sockets is not a beginning Java concept, so I'll move the thread to the sockets forums and also to Java in General, in case there are other ways to tackle this problem.
 
Sheriff
Posts: 24366
55
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want a client written in Java to execute a method remotely in a server also written in Java, then RMS is a Java tool which allows you to do that. (Also not a beginning Java concept.)
 
Dave mann
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Knute Snortum wrote:There may be other ways to do this, but I would use sockets.  Sockets is not a beginning Java concept, so I'll move the thread to the sockets forums and also to Java in General, in case there are other ways to tackle this problem.



thats what I am getting also, seems like Socket programming is the only or most common way, I am into it now, just wondering if maybe someone with experience in that matter could share.

Paul Clapham wrote:If you want a client written in Java to execute a method remotely in a server also written in Java, then RMS is a Java tool which allows you to do that. (Also not a beginning Java concept.)



RMS = Record Management System ? thats what I am getting on search engine, or not ?
 
Paul Clapham
Sheriff
Posts: 24366
55
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dave mann wrote:RMS = Record Management System ? thats what I am getting on search engine, or not ?



Sorry... too much Christmasery has dulled my brain today. RMI is what I should have said.

But I think it would be a good idea at this point to ask -- why do you want to do this particular thing?

(It often happens that people are trying to do something which looks like it's off the wall because they're really trying to do something ordinary but have gone directly down a blind alley.)
 
Dave mann
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Paul Clapham wrote:

Dave mann wrote:RMS = Record Management System ? thats what I am getting on search engine, or not ?



Sorry... too much Christmasery has dulled my brain today. RMI is what I should have said.

But I think it would be a good idea at this point to ask -- why do you want to do this particular thing?

(It often happens that people are trying to do something which looks like it's off the wall because they're really trying to do something ordinary but have gone directly down a blind alley.)



Okay, noted.

and I am going to explain intention or goals.

I want to create a 'simple' Queue Management or at least a smaller part of the management system, it will have a PC with a Java program on it which will act as a Server, this java desktop program will have a Main Display showing a number representing a Queue Number.

then there will be 1 or more other Computer in the same LAN network that will act as clients, each Computer will have a separate Java Desktop program, which has a jButton let say called as NextButton, let say Client#1 pressed the jButton on his PC, then this jButton on the Java desktop app will send an instruction or a command for the Java Desktop app on the Server PC to increment the Queue Number showed in the Main Display Displayed by Server PC.

That is the kind of system I am trying to develop or at least figure out in my mind, I have no other people here who understand or ever want to dwell with Java as deep as myself, commonly people here only dwell in VB.net

I hope my explained clearly, I am not fluent in english.
 
Saloon Keeper
Posts: 5395
143
Android Firefox Browser Mac OS X Safari Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Web services may also be a viable approach. They're often easier to set up on a network than sockets due to firewalls etc. between the machines.
 
Saloon Keeper
Posts: 20639
122
Android Eclipse IDE Java Linux Redhat Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Raw sockets are the lowest overhead, but require the most coding, debugging, and ongoing support.

RMI is a good choice here because everything's in-house. RMI isn't such a good choice over the open Internet, however.

CORBA is a language-independent alternative to RMI, but I think we can count CORBA as being thoroughly dead at this point.

Remote EJB is an option if the receiving server is already a full-stack webapp server, EJB is essentially RMI with extended capabilities (and security features).

A Web Service is an option for when the receiving server is a webapp server, but not full-stack (like Tomcat or jetty) or where you can't be bothered to set up an EJB. Or you want language independence in the post-CORBA world. Or you need machines on the open Internet to talk (through firewalls). Web Services can be further subdivided into SOAP (rarely worth the overhead) and ReST.

JMS or MQ could do it, but they seem like overkill for just 2 programs and one method. Plus the coding isn't a simple remote method call here.


My own pick here would be RMI, but if you want something that can be maintained by cheap interns, a ReST web service would be my second choice.
 
Ranch Hand
Posts: 154
5
MS IE Notepad Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, according to many possible solutions - this comes down to "What you want to accomplish?". Just to puzzle together a few lines just to implement a counter wich can be triggered remotely by different clients can be done in PHP. The question arises: What do you want to do with this counter? Are the clients supposed to get the number back? Is the main server instance supposed to do something with the clients or thier requests in the order they increased the counter so they build a distributed synched queue?
 
Tim Holloway
Saloon Keeper
Posts: 20639
122
Android Eclipse IDE Java Linux Redhat Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To expand on Matt's solution: He's apparently saying that there's no need to install a Java application on each client computer. Just create a webapp and let the clients invoke it.

That's generally the preferred approach these days, since you don't have operating system dependencies or library requirements or the need to somehow install a copy of the application on each desktop.

Of course, it's also presuming that that's all you want the app to do. If you have a complex app, and that's just one function, it might not be practical to do it as a webapp. Although these days webapps can do probably at least half the things that desktop apps used to do. And often do them better, if you're running in an enterprise, where security and data backup functions are important, since neither of these requirements tend to be well-handled in desktop apps.

I used to use PHP myself for this sort of thing, although NodeJS is my frequent choice for minimal web-service apps. In either case (and, for that matter, a full J2EE webapp), a desktop client app for a web-services function can be in whatever language you are comfortable with, including VB.Net.
 
Dave mann
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you mean web services = web app ?

The thing is, I dont have any better knowledge in web programming, I know a lil bit of PHP but thats it for now, I think my best shot for now is doing it with Java.

 
Tim Moores
Saloon Keeper
Posts: 5395
143
Android Firefox Browser Mac OS X Safari Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Web services could be implemented in the form of a Java web app, yes. The JAX-RS API (the standard Java API for RESTful web services) makes that fairly easy. "web app" in this context has nothing to do with HTML etc. - which I guess you mean by "web programming".
 
Dave mann
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Moores wrote:Web services could be implemented in the form of a Java web app, yes. The JAX-RS API (the standard Java API for RESTful web services) makes that fairly easy. "web app" in this context has nothing to do with HTML etc. - which I guess you mean by "web programming".



never touched Java EE yet, only SE or Desktop, I am in the middle in getting my way through the RMI pathway right now, do you think it would be better for me to switch to java web services at this moment or keep on going with the current RMI thingy ?
 
Tim Moores
Saloon Keeper
Posts: 5395
143
Android Firefox Browser Mac OS X Safari Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, RMI is a fairly low overhead approach to getting Java code to run on a remote host. If the port issue is no problem, and you have never had to deal with Java web apps (and the related servers like Tomcat), then RMI is probably the simpler approach.

But in general, RMI has fallen out of favor and been replaced with web services, implemented in Java or some other language. Just something to keep in mind going forward.
 
Dave mann
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Moores wrote:Well, RMI is a fairly low overhead approach to getting Java code to run on a remote host. If the port issue is no problem, and you have never had to deal with Java web apps (and the related servers like Tomcat), then RMI is probably the simpler approach.

But in general, RMI has fallen out of favor and been replaced with web services, implemented in Java or some other language. Just something to keep in mind going forward.



ah okay, I guess thats why I haven't heard about it before this, I guess I'lll just finish this, and switch to web services after that. Thnks for the head up.
 
Tim Holloway
Saloon Keeper
Posts: 20639
122
Android Eclipse IDE Java Linux Redhat Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One thing to note about RMI, though.

RMI communications are done by serializing objects. And while Java on the whole is extremely backwards compatible, the internal formats of serialized Java can be incompatible, in which case a transmission using a non-compatible serialization version can cause the client or server to throw an exception. So you do need to ensure that the JVMs running both client(s) and server are kept in sync with each other.

Also, while you can run an RMI server as a simple dedicated Java application, it's also possible to run it as a service of something more complex. For example, Apache Karaf or ServiceMix. This is a worthwhile consideration if you have other odd stand-alone Java apps and you would like to keep them all in one place under one control instead of splattering them all over the server machine. And ServiceMix has the advantage that you can plug a webserver module into it if you need simple webapp services.
 
Dave mann
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Tim, thnks for the tips.

I am getting the hang of it.

But now, I have created 2 Pair of Java RMI server-client app.

Pair #1 is super simple, it just invoke methods on the server, and succesfully ran as it should be.

Pair #2 is asimilar, it just one of the remote method is Accessing the mysql db.

and Pair#2 isnt working, first I got UnmarshalException "No Security Manager: RMI Class Loader disabled".
After I added some Security manager line

if(System.getSecurityManager() == null {
  System.setSecurityManager(new SecurityManager());
}

, I got "access denied(127.0.0.1:22070 listen, resolve,)

yeah, you are right, this thing is very Tricky I guess ?

do you think I should upload my codes here ? I am kinda confused.
 
Knute Snortum
Sheriff
Posts: 5917
155
Chrome Eclipse IDE Java Postgres Database Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I haven't used RMI a lot, but I would imagine that posting to a database would be a restricted activity.  Allowing a remote system to update your database seems like a security risk.
 
Tim Holloway
Saloon Keeper
Posts: 20639
122
Android Eclipse IDE Java Linux Redhat Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An RMI server is a standard Java application, so like any stand-alone Java application, it can connect to a database directly or using a Connection Pool (you have to provide your own, however, RMI doesn't cover that). Unless, of course, you override the standard sandbox rules.

The fact that a remote client is invoking the method doesn't matter any more than it would if a remote web client invoked a webapp server-side task that communicated with a database. However, the RMI method itself may require some sort of security, and in fact, that's one of the things that remote EJBs add over straight RMI. With plain old RMI, the only security you have is your firewall and whatever security code you provide yourself (Spring Security might be an option here).
 
Dave mann
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I gotta correct that, now Ive made another similar simple RMI server-client pair app, with even same level of method, no database access, now all of these app got the same error, event the previous one that was perfectly working. where can I see the complete documentation or anyone who is in full depth knowledge of this RMI thing ? cases I saw online most of em still confused with this security things.
 
Dave mann
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Knute Snortum wrote:I haven't used RMI a lot, but I would imagine that posting to a database would be a restricted activity.  Allowing a remote system to update your database seems like a security risk.



Sorry, I didnt mean by directly accessing database, but once a Client does an RMI call to the RMI Server, the RMI server will access and insert a value into the database before it could then send back the same value to the calling client, the reason the value need to be inserted into database because it will later be accessed by another client on a different JVM on a different PC.
 
Tim Holloway
Saloon Keeper
Posts: 20639
122
Android Eclipse IDE Java Linux Redhat Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, that's interesting. This is the first I'd heard of being able to run RMI over SSL.

The approach you mentioned will prevent external listeners from snooping over an RMI connection, but you'll also want to incorporate some sort of mechanism to identify which user is which. And ideally to limit who can connect, although there's a lot of "security through obscurity" with RMI/SSL simply because almost nobody would expect to see such a thing.
 
Dave mann
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Holloway wrote:Well, that's interesting. This is the first I'd heard of being able to run RMI over SSL.

The approach you mentioned will prevent external listeners from snooping over an RMI connection, but you'll also want to incorporate some sort of mechanism to identify which user is which. And ideally to limit who can connect, although there's a lot of "security through obscurity" with RMI/SSL simply because almost nobody would expect to see such a thing.



very nice, but I still stuck in the Security problem though, Now Sockets look easier.
 
Paul Clapham
Sheriff
Posts: 24366
55
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dave mann wrote:very nice, but I still stuck in the Security problem though, Now Sockets look easier.



I searched the web a bit and found this post on another forum: Java RMI To use SecurityManager or not to use SecurityManager. The answer is pretty terse -- but it might not apply if you want to use SSL for transmission.

But I notice in the Oracle link you posted that there's a policy file which controls what the security manager will permit. Possibly you might just need to modify it to include the permissions which the security manager complains about?
 
Knute Snortum
Sheriff
Posts: 5917
155
Chrome Eclipse IDE Java Postgres Database Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dave mann wrote:...I still stuck in the Security problem though, Now Sockets look easier.


Well, you'll have to deal with SSL if you use sockets too.
 
Dave mann
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Paul,

Yeap, I've came across that link also, the problem is, I dont know how to properly disable or ( Not to Use ) Security Manager, or how to deactivate it or exclude it from RMI, because when the first time I tried this, I didnt even knew about it, I get to realized that it is existed the first time I got the "No security Manager, RMI class Loader disabled" exception message.

So I guess it's a standard feature that is forced to be enabled by Java by default. maybe I am wrong, but thats the only possible conclusion that I can take for now after stumbling on these RMI Sec Manager related threads all over the internet.
 
Dave mann
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Knute Snortum wrote:

Dave mann wrote:...I still stuck in the Security problem though, Now Sockets look easier.


Well, you'll have to deal with SSL if you use sockets too.



I tried make a simple one 2 days ago, and it worked like a charm, an intro to the RMI made its easier to kinda understand the socket programming, though its not the same.
the important part is I haven't encountered any of the similar problem to security problems I faced in RMI.
 
Paul Clapham
Sheriff
Posts: 24366
55
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dave mann wrote:I dont know how to properly disable or ( Not to Use ) Security Manager, or how to deactivate it or exclude it from RMI...



So have you tried modifying the policy file to permit the actions it's presently not permitting?
 
Dave mann
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Paul Clapham wrote:

Dave mann wrote:I dont know how to properly disable or ( Not to Use ) Security Manager, or how to deactivate it or exclude it from RMI...



So have you tried modifying the policy file to permit the actions it's presently not permitting?



I tried with granting all permissions, but still producing the same error.
 
Dave mann
Ranch Hand
Posts: 35
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, now I almost finished with the app that I mentioned I am building, which was failed previously on RMI because of lack of understanding the tricky part of the security manager, its now using Sockets, and working as I need it to be. Thnks for the Awesome Answers, but I'll back again on the RMI one as soon as i finished the socket one and set it up running.
 
Paul Clapham
Sheriff
Posts: 24366
55
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good to hear you're making progress!
 
Dave mann
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah Thanks, Everything looks fine, and it should be done and ready for testing on weekend.
 
No. No. No. No. Changed my mind. Wanna come down. To see this tiny ad:
Create Edit Print & Convert PDF Using Free API with Java
https://coderanch.com/wiki/703735/Create-Convert-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!