I tried to implement UDP server using Spring Integration like it's described here but when clients operate behind NAT they will never receive responses from server. It's because server should send response datagrams from the same port as UDP adapter port (check UDP via NAT explained here).
How can I achieve proper UDP communication with clients behind NAT using Spring Integration?
As discussed in those threads; there are not currently any gateways for UDP, only channel adapters. Gateways are used for two-way integration.
There has just not been any demand over the years for UDP gateways.
We did make some changes to facilitate users replying to incoming messages (by adding the sending port as as header).
This will allow you do construct a DatagramPacket
(perhaps using the SI DatagramPacketMessageMapper
) and send it to the originating system using your own code.
If you want us to reconsider providing UDP gateways, make a comment on the JIRA Issue. Even better, consider contributing.
EDIT
For asynchronous sends you don't need a gateway; buy you need to tweak the mapper and message handler which is built into the outbound adapter.
Change the DatagramPacketMessageMapper
here to set the socketAddress
using message headers; and add an option to the UnicastSendingMessageHandler
so that it doesn't unconditionally set the destinationAddress
here.
You can do this by subclassing the handler and overriding the send()
method.
You can then wire your customized message handler into a <service-activator/>
using the ref
attribute.