编程语言
首页 > 编程语言> > java-如何发送对TCP请求的答复(spring-integration)?

java-如何发送对TCP请求的答复(spring-integration)?

作者:互联网

我需要类似Can not send response for UDP message的内容
但对于TCP.因此客户端发送消息,TCP服务器可以像OK一样发送回响应.对于TCP socket-expression =“ @ inbound.socket”和destination-expression =“ headers [‘ip_packetAddress’]”无法使用.

这是我的配置现在的样子:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:int="http://www.springframework.org/schema/integration"
    xmlns:int-ip="http://www.springframework.org/schema/integration/ip"
    xmlns:int-event="http://www.springframework.org/schema/integration/ip"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
        http://www.springframework.org/schema/integration/ip http://www.springframework.org/schema/integration/ip/spring-integration-ip.xsd">

  <int:channel id="tcpSend"/>

  <int-ip:tcp-connection-factory id="client" type="client"/>

  <int-ip:tcp-connection-factory id="server" type="server" host="localhost" port="1234"/>

  <int-ip:tcp-outbound-channel-adapter id="tcpOutbound" channel="tcpSend"
                                   connection-factory="client"/>

  <int-ip:tcp-inbound-channel-adapter id="tcpInbound" channel="tcpReceive"
                                  connection-factory="server"/>

  <int:service-activator id="tcpHandler" input-channel="tcpReceive" output-channel="tcpSend"
                         ref="listener"/>
</beans>

解决方法:

如果使用TCP,则更容易,因为您可以使用Inbound Gateway.

关于此事的样本在官方资料库中:https://github.com/spring-projects/spring-integration-samples/tree/master/basic/tcp-client-server

标签:sockets,tcp,spring,java,spring-integration
来源: https://codeday.me/bug/20191111/2019486.html