使用码头接收非Http消息 [英] Receive non Http messages using jetty

查看:248
本文介绍了使用码头接收非Http消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过Java使用嵌入式码头和Spring进行Java到Java的通信。我的问题是我的服务器应用程序还必须在同一端口上处理普通的TCP消息。

I am using embedded jetty and spring for java to java communication over http. My problem is that my server application must handle plain TCP messages also on the same port.

是否有一种方法可以检测到TCP消息是否到达,而该消息不能由服务器处理。 servlet?

Is there a way to detect if a TCP message arrived which cannot be handled by the servlet?

感谢您提供更多详细信息:

Thanks for the answers I add some more details:


  • I无法修改客户端。原因是旧版本的客户端使用纯Java tcp套接字,结果是新服务器必须与旧客户端向后兼容。

  • 必须使用相同版本port

  • 旧客户端消息是通过简单套接字的短序列化文本。 1:打开连接,2:发送文本,3:关闭连接

  • 我的服务器如下所示: http://kielczewski.eu/2013/11/using-embedded-jetty-spring-mvc/

  • 我不需要解析消息。只需检测到未使用http的邮件到达并获取源主机名即可。

  • I cannot modify the client. The reason for this is that the old version of the client uses pure java tcp socket and it turned out that the new server must be backward compatible with the old client.
  • Have to use the same port
  • Old client messages are short serialized text over simple socket. 1: open connection, 2: send text, 3: close connection
  • My server looks something like this: http://kielczewski.eu/2013/11/using-embedded-jetty-spring-mvc/
  • I do not need to parse the message. It is enough to detect that a message was arrived which is not using http and get the source host name.

推荐答案

您可能想看看如何添加自定义 ConnectionFactory ServerConnector 您的HTTP端口。

You might want to take a look at how to add a custom ConnectionFactory to the ServerConnector of your HTTP port.

这个 ConnectionFactory 概念是Jetty当前如何支持 PROXY 协议的。

This ConnectionFactory concept is how the PROXY Protocol is supported within Jetty currently.

在您的情况下,您可能会遇到...

In your case, you might have something like ...

MyTcpConnectionFactory tcpConnectionFactory = new MyTcpConnectionFactory();
ServerConnector http = new ServerConnector(server);
http.addFirstConnectionFactory(tcpConnectionFactory);
server.addConnector(http);

在您的情况下,您将覆盖 newConnection(连接器连接器,EndPoint endPoint )方法并实现对TCP流或HTTP流的检查。

In your case, you would override the newConnection(Connector connector, EndPoint endPoint) method and implement the check for your TCP flow, or the HTTP flow.

如果是您的流,则可以处理该连接上的通信自己,然后在完成时抛出IOException,指示您不希望码头将连接作为HTTP处理。

If its your flow, you handle the communications on that connection yourself and then throw an IOException when you are done indicating that you don't want jetty to process that connection as HTTP.

否则,您将Connection对象返回给码头以进行处理作为HTTP。

Otherwise you return that Connection object to Jetty to process as HTTP.

这篇关于使用码头接收非Http消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆