Browse DevX
Sign up for e-mail newsletters from DevX


Cross the Gap Between PHP and Java : Page 4

Using sophisticated application frameworks to build your network server applications is fine, but sometimes these frameworks are overkill. With a little communications programming between PHP and Java, you can establish an extensible layer that handles the annoying details of creating a custom network protocol.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

A Mechanism for Ad-hoc Remote Procedure Calls
If the communication between PHP and Java teach you anything, it is the importance of using an abstraction layer to hide messy and unimportant details. In this case, you were able to turn the simple function of adding two numbers into a full-fledged, multi-threaded network service, while keeping the actual addition code very simple and clean. The communication details were hidden away in specialized classes, which can be re-used for any other network service.

What you've actually built is an ad-hoc remote procedure call (RPC) mechanism. RPC systems can be pretty complicated, but you avoided that by both making your system simple and robust, and allowing for very general data structures.

The downside is your network protocol is a bit wasteful on bytes, but that is probably not a concern for simple applications. And if it does become a problem, you can always change the protocol layer—without having to disrupt the application code. The code in this article can also serve as an excellent tool for rapid prototyping.

Greg Travis is a freelance Java programmer and technology writer living in New York City. After three years in the world of high-end PC games, he joined EarthWeb, where he developed new technologies with the then-new Java programming language. Since 1997, he has been a consultant in a variety of Web technologies. .
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date