简体   繁体   中英

Socket or HTTP POST Request?

This is somewhat similar to a previous posting but focuses on a specific aspect because I really to know the answer to this specific question before I can even move forward at this point. I need to send information in the form of a JSON object from a Java SE application to a Java EE web application. The Java EE web application is running from NetBeans in GlassFish. Both the Java SE and Java EE applications are running on the same computer.

What would be the best means to communicate between the two applications considering that they are both on the same computer: a socket connection, an http post request connection, or a combination of socket and http post request connection?

I would really appreciate any responses.

Choosing between a self implemented socket or use HTTP if you are already using Glassfish is a no-brainer: Use HTTP.

Glassfish has already proved and tested code to talk to clients via a socket connection, implemented the HTTP protocoll, uses thread pools, etc. The only thing you have to do is to implement a small Servlet class abstracting all the complicated transportation details away.

On client side you can use a library like Apache HTTP client .

Sure you can use plain sockets. But do you want to implement your own protocol? Why? And then it might work for client and server on the same computer. But maybe later you want to use a connection over the internet with proxy server or a firewall between. With HTTP using the right libraries this is no problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM