简体   繁体   English

Fat Java客户端需要通过http / https到Web服务器的双向通信通道

[英]Fat Java client need two-way communication channel to web server over http/https

I have a situation where I want a Java client to have a two-way data channel with a servlet (I have control over both), so that either can begin data transferring without having to wait for the other to do something first, but to get through the firewalls this needs to be tunnelled in http or https. 我遇到的情况是,我希望Java客户端具有一个带有Servlet的双向数据通道(我对两者都有控制权),这样任何一个都可以开始传输数据,而不必等待另一个先做,而是通过防火墙,这需要在http或https中进行隧道化。

I have looked around, but I do not believe I know the right terms for asking Google. 我环顾四周,但我不认为我知道询问Google的正确条件。

I was originally looking at http-tunneling modules, but realizing that I have a web container in the other end, I believe that the appropriate way is to think of a fat client needing to communicate home. 我最初查看的是http-tunneling模块,但是意识到我在另一端有一个Web容器,所以我认为适当的方法是考虑胖客户端需要在家进行通信。 I was thinking that the persistant connection in http 1.1 might be very useful here. 我当时认为http 1.1中的持久连接在这里可能非常有用。 I can easily do heartbeat transfers to keep the connection from ideling. 我可以轻松进行心跳传输,以保持连接畅通无阻。

At this point in time I just need to do a proof of concept so I primarily need something that works now, which can then be optimized or even replaced later. 在这一点上,我只需要做一个概念证明,因此我首先需要现在可以工作的东西,然后可以对其进行优化甚至替换。

So, I'd appreciate pointers to projects that allow me to have a connection where either side can at will push information (like a serialized object or a descriptive stream of bytes) to the other side. 因此,我很感谢指向项目的指针,这些项目使我能够建立连接,任何一方都可以将信息(例如序列化对象或字节的描述性流)推送到另一方。 I'd prefer pure Java, if at all possible. 如果可能的话,我更喜欢纯Java。


EDIT: Thanks for the pointers. 编辑:感谢您的指针。 It appears that what I need, will be available in the servlet 3.0 specification, which I might end up using in the long term depending on when it will be supported in the various web containers. 看来,我所需要的将在Servlet 3.0规范中提供,我可能最终会长期使用它,具体取决于各种Web容器何时支持它。

For now I am investigating the Cometd package, which appears to be able to do exactly what I need for my prototype. 目前,我正在研究Cometd程序包,该程序包似乎能够完全满足我的原型所需。

Search terms: comet, long-polling 搜索字词:彗星,长轮询

These are mostly used in an AJAX context, but I see no reason why you could not use them in a Java project. 这些大多用于AJAX上下文中,但是我看不出为什么不能在Java项目中使用它们。

Please take a look at Eclipse Net4J, 请看一下Eclipse Net4J,

http://wiki.eclipse.org/Net4j http://wiki.eclipse.org/Net4j

It supports all the features you mentioned. 它支持您提到的所有功能。 A special nice feature is that it supports HTTP connection pooling so you can have lots of channels between client and server but use only a few HTTP connections. 一个很好的特殊功能是它支持HTTP连接池,因此您可以在客户端和服务器之间建立许多通道,但仅使用几个HTTP连接。

The only problem is that it doesn't have documentation at all. 唯一的问题是它根本没有文档。 You just have to read the source code. 您只需要阅读源代码。 Once you figure it out, it's very easy to use. 一旦弄清楚了,就很容易使用。

There are a few more diagrams on old Net4J site, 旧的Net4J网站上还有一些图表,

http://net4j.berlios.de/ http://net4j.berlios.de/

How fast does it need to be? 它需要多快? You could always just do polling on the client. 您总是可以在客户端上进行轮询。 Just check for new messages every so often. 只要经常检查新消息。

You can use the Hessian protocol over HTTP. 您可以通过HTTP使用Hessian协议。 It's a fast binary protocol for serializing data. 这是用于序列化数据的快速二进制协议。 Typically used for a web-services style RPC communication, but there's no reason it couldn't be 2-way - see Hessian mux . 通常用于Web服务风格的RPC通信,但是没有理由不能采用2向方式-请参见Hessian Mux It's pure Java, too :-) 它也是纯Java的:-)

Generally this is done by having the server not respond to an http request immediately. 通常,这是通过使服务器不立即响应http请求来完成的。 It waits around for some update (or a timeout) before sending a response. 在发送响应之前,它会等待一些更新(或超时)。 Obviously some care needs to be made ensuring that the server will handle this under load. 显然,需要格外小心,以确保服务器可以在负载下处理此问题。

See, for instance, Comet . 例如,参见Comet

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

相关问题 与Java线程的双向通讯 - Two-way communication with a Java thread 为什么我的 UDP 客户端/服务器数据报没有进行双向通信? - Why my UDP client/server datagram is not operating the two-way communication? 需要使用双向SSL安全Web服务的Java客户端Destop App的示例 - Need example of Java Client Destop App consuming Two-way SSL Secured webservice SSL客户端(Java)不在两次SSL握手中将证书发送回服务器 - SSL client (Java) is not sending a certificate back to the server in two-way SSL handshake 我的 SSL 客户端 (Java) 未通过双向 SSL 握手将证书发送回服务器 - My SSL client (Java) isn't sending a certificate back to the server in two-way SSL handshake 使用双向身份验证连接到服务器时 Java 测试客户端中的 SSL Handshake_failure - SSL Handshake_failure in Java test client while connecting to server with two-way authentication 通过Java中的双向客户端-服务器交互发送IP地址 - Sending the IP address via two-way client-server interaction in Java gSOAP客户端和Java Web服务之间通过HTTPS进行的通信 - Communication between gSOAP client and Java webservice over HTTPS 与Tomcat的双向SSL通信 - Two-way SSL communication with Tomcat 客户端-服务器双向通讯 - Client-server two way communication
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM