Can not send response for UDP message

回眸只為那壹抹淺笑 提交于 2019-12-24 20:46:51

问题


I am trying to send message with:

netcat -u localhost 11111abcd

I just need that the client get answer: OK It get the message and try to answer with OK. But it writes this infinitely to application log:

Message: GenericMessage [payload=byte[2], headers={ip_packetAddress=127.0.0.1/127.0.0.1:49489, ip_address=127.0.0.1, id=8db6aa3b-b56b-6dce-9554-c7b0ce050142, ip_port=49489, ip_hostname=127.0.0.1, timestamp=1494442285767}]

Message Payload: OK

Config:

<?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;
}

回答1:


Your outbound adapter is sending messages to the inbound adapter. If you want to reply to a packet, you need to configure the socket and destination expressions. See the documentation.

<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" />


来源:https://stackoverflow.com/questions/43900627/can-not-send-response-for-udp-message

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!