gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 02:33:55 25 4
gpt4 key购买 nike

我需要类似于 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

关于java - 如何发送 TCP 请求的回复(spring-integration)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43903702/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com