简体   繁体   中英

Creating a simple Java web server

I'm trying to create a tiny web server to route information between client applications for a Diffie-Hellman Key Exchange encryption system. Sadly, I have very little experience with Java networking. What would be the best way to set up a server to receive values from user A and pass it onto user B, and vice versa? I've looked into servlets with Tomcat/Google App Engine, but they appear to be mainly dealing with HTML webpages. I've tried using sockets, but I am not sure if I can host a ServerSocket application on the internet.

What is the best way to achieve this goal?

I've looked into servlets with Tomcat/Google App Engine, but they appear to be mainly dealing with HTML webpages.

That is incorrect.

While it is true that most examples you will find deal with HTML webpages, the Servlet framework is equally suited to sending non-HTML responses; eg JSON, XML ... or basically anything that you can turn into a bytestream.

I've tried using sockets, but I am not sure if I can host a ServerSocket application on the internet.

Implementing an HTTP server at the Socket level is significant amount of work to do properly ... including a lot of HTTP specification reading! Frankly, it is not worth the pain and effort unless you have extreme performance requirements. (And if you do, you probably shouldn't be using Java ...)

What is the best way to achieve this goal?

For something simple without onerous performance requirements, an stock servlet container like Tomcat, Jetty or GAE should be fine.

IMO:

When we have two applications and they want to communicate with each other, then we make use of web services. You can make use SOAP based WSDL webservices or RESTful webservices. Later is more popular now a days.

Making use of existing frameworks will make your life easier without having to re-invent the wheel.

All the best.

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