简体   繁体   English

创建一个简单的Java Web服务器

[英]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. 我正在尝试创建一个小型Web服务器,以在Diffie-Hellman密钥交换加密系统的客户端应用程序之间路由信息。 Sadly, I have very little experience with Java networking. 不幸的是,我对Java网络的经验很少。 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? 设置服务器以从用户A接收值并将其传递给用户B,反之亦然的最佳方法是什么? I've looked into servlets with Tomcat/Google App Engine, but they appear to be mainly dealing with HTML webpages. 我已经研究了使用Tomcat / Google App Engine的servlet,但是它们似乎主要用于处理HTML网页。 I've tried using sockets, but I am not sure if I can host a ServerSocket application on the internet. 我尝试使用套接字,但是不确定是否可以在互联网上托管ServerSocket应用程序。

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. 我已经研究了使用Tomcat / Google App Engine的servlet,但是它们似乎主要用于处理HTML网页。

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; 的确,您会发现大多数示例都涉及HTML网页,但Servlet框架同样适用于发送非HTML响应。 eg JSON, XML ... or basically anything that you can turn into a bytestream. 例如JSON,XML ...或基本上可以转换为字节流的任何内容。

I've tried using sockets, but I am not sure if I can host a ServerSocket application on the internet. 我尝试使用套接字,但是不确定是否可以在互联网上托管ServerSocket应用程序。

Implementing an HTTP server at the Socket level is significant amount of work to do properly ... including a lot of HTTP specification reading! 要在Socket级别实现HTTP服务器,需要做大量工作才能正常工作……包括阅读许多HTTP规范! 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 ...) (如果这样做,您可能不应该使用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. 对于没有繁重性能要求的简单操作,应该使用诸如Tomcat,Jetty或GAE之类的普通servlet容器。

IMO: 海事组织:

When we have two applications and they want to communicate with each other, then we make use of web services. 当我们有两个应用程序并且它们想要彼此通信时,我们就使用Web服务。 You can make use SOAP based WSDL webservices or RESTful webservices. 您可以使用基于SOAP的WSDL Web服务或RESTful Web服务。 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. 祝一切顺利。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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