Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Integration UDP server for clients behind NAT

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?

like image 587
yu55 Avatar asked Dec 03 '25 09:12

yu55


1 Answers

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.

like image 60
Gary Russell Avatar answered Dec 06 '25 12:12

Gary Russell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!