Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP accessing java object via socket?

Status
Not open for further replies.

jisoo23

Programmer
Joined
Jan 27, 2004
Messages
192
Location
US
Hello all,

I have a question concerning access to Java Objects via a PHP interface. If I were to have a persistent Java Object running on a Linux computer (perhaps running in an infinite loop?) would I be able to access the data/methods of that java object via PHP using a socket connection? I see that there are some PHP functions pertaining to functions so I assume that this is possible. If so, what would be the correct syntax for invoking a Java method? For example, if my java class had a method "getString()" which returned a string value (like "Hello World"), how would I call it from the PHP end? Any ideas or suggests are appreciated.

Thanks!
Jisoo23
 
No. Just having the app running is not enough.

It might be possible if and only if the Java app in question were listening on a socket and if it provided functionality of allowing remote procedure calls through that interface.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Hello,

Thanks for the quick reply! Sorry I'm afraid I didn't describe my question quite well enough. The java application would indeed be assigned a socket to listen to (maybe 9999 or something). I'm pretty new to using sockets in Java or PHP so please bear with me.

You mention that it may be possible if the functionality of allowing remote procedure calls was built into the java app. How would I accomplish this? The only way I know of is using the CLI and STDIN/STDOUT but somehow I don't think that's quite enough. Theoretically there would be many accesses to this java object via that socket so it would have to be pretty fast and robust. Has you or anyone heard of such a thing?

Thanks,
Jisoo23
 
How that Java app must be designed and built is outside the scope of this forum, except to say that it must implement some protocol for accessing the functions of an object of the app -- SOAP or XMLRPC.

Then you have to implement the same protocol on the PHP side.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Ok thanks for the ideas! I'll be reading up on socket programming and probably XMLRPC then. If I have any more questions, I'll move this to the Java(SUN) forum.

Jisoo23
 
How about setting up some sort of propriatery protocol to communicate between PHP and Java using the socket and strign messages. This would be a simple solution as your PHP app would only have to parse the string replies coming back from the JAVA app on the other end. This is not recommended if you are trying to do a full fledged Remote Method Invocation in JAVA.


Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top