Java 无法发送UDP消息的响应
我正在尝试通过以下方式发送消息:Java 无法发送UDP消息的响应,java,spring,networking,udp,spring-integration,Java,Spring,Networking,Udp,Spring Integration,我正在尝试通过以下方式发送消息: netcat -u localhost 11111abcd 我只需要客户得到答案:好,它得到的消息,并试图回答与确定。 但它会无限地将其写入应用程序日志: 消息:GenericMessage[payload=byte[2],headers={ip_packetAddress=127.0.1/127.0.0.1:49489,ip_address=127.0.0.1,id=8db6aa3b-b56b-6dce-9554-c7b0ce050142,ip_端口=494
netcat -u localhost 11111abcd
我只需要客户得到答案:好,它得到的消息,并试图回答与确定。
但它会无限地将其写入应用程序日志:
消息:GenericMessage[payload=byte[2],headers={ip_packetAddress=127.0.1/127.0.0.1:49489,ip_address=127.0.0.1,id=8db6aa3b-b56b-6dce-9554-c7b0ce050142,ip_端口=49489,ip_主机名=127.0.0.1,时间戳=149442285767}]
消息有效负载:OK
配置:
<?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: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="sendUdp"/>
<int-ip:udp-outbound-channel-adapter id="udpOut" host="localhost" port="11111"
multicast="false" check-length="false"
channel="sendUdp" />
<int-ip:udp-inbound-channel-adapter id="udpIn" port="11111" receive-buffer-size="500"
multicast="false" check-length="false"
channel="receiveUdp"/>
<int:service-activator id="updHandler" input-channel="receiveUdp" output-channel="sendUdp" ref="listener"/>
</beans>
@ServiceActivator
public String handle(Message<?> message) {
System.out.println("*** Message: " + message);
String command = new String((byte[]) message.getPayload());
System.out.println("*** Message Payload: "
+ command);
String response = "OK";
return response;
}
@服务激活器
公共字符串句柄(消息){
System.out.println(“***消息:“+消息”);
String命令=新字符串((字节[])message.getPayload());
System.out.println(“***消息负载:”
+指挥部);
字符串响应=“确定”;
返回响应;
}
出站适配器正在向入站适配器发送消息。如果要回复数据包,需要配置套接字和目标表达式。看
这难道不意味着您要对出站通道适配器向其发送消息的端口使用入站通道适配器进行循环吗?
<int-ip:udp-inbound-channel-adapter id="inbound" port="11111" channel="in" />
<int:channel id="in" />
<int:transformer expression="new String(payload).toUpperCase()"
input-channel="in" output-channel="out"/>
<int:channel id="out" />
<int-ip:udp-outbound-channel-adapter id="outbound"
socket-expression="@inbound.socket"
destination-expression="headers['ip_packetAddress']"
channel="out" />