Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SimpleChannelInboundHandler<DatagramPacket> added in the pipeline does not work #11

Open
arunp1990 opened this issue May 2, 2021 · 4 comments

Comments

@arunp1990
Copy link

arunp1990 commented May 2, 2021

There is a requirement in my project to obtain Host Address of the sender from the UDP Header for processing the request. As per my understanding, I need to add a handler using which I will get DatagramPacket. So, I modified the usage example given in https://github.com/Shevchik/UdpServerSocketChannel by replacing:
private static class Echo extends SimpleChannelInboundHandler
with
public static class Echo extends SimpleChannelInboundHandler.

The modified example is attached.

But, protected void channelRead0(ChannelHandlerContext channelHandlerContext, DatagramPacket datagramPacket) throws Exception is not invoked at all. It may be because the library (UdpServerSocketChannel) already has a similar handler

:
protected class ReadRouteChannelHandler extends SimpleChannelInboundHandler {

Can you please let me know if the above solution which I am trying can be made to work? If not, please let me know any alternate solution which I can try.

Thanks!

ExampleUdpServer.txt

@Shevchik
Copy link
Owner

Shevchik commented May 2, 2021

No. Thats literally a part of the readme about channel per remote address and using channel remote address for that.
If you dont plan on making a stateful udp connection, you should just use the normal netty datagram channel.

@arunp1990
Copy link
Author

Thanks for the quick reply!

I would like to explain the scenario which I am trying to solve. The UDP server which uses your library is behind a load balancer. So, the channel remote address is the ip address of the Load Balancer. But, I have to obtain the IP address of the client which sent the request.

I noticed that p.sender() is used for computation in

UdpChannel channel = userChannels.compute(p.sender(), (lAddr, lChannel) -> {

But, for removal , channel's remoteAddress is used.
userChannels.compute((InetSocketAddress) userChannel.remoteAddress(), (lAddr, lChannel) -> lChannel == userChannel ? null : lChannel);

If the UDP server is behind a Load Balancer, p.sender() and userChannel.remoteAddress() will be different as per my understanding. p.sender() will be the IP address of the client which sent the request. userChannel.remoteAddress() will be the IP address of the Load balancer. Please correct me if I am wrong.

@Shevchik
Copy link
Owner

Shevchik commented May 2, 2021

The user channel remote address is literally the datagram sender address. So they will always the the same. That's literally the whole point of this library, every new sender address allocates a new user channel.

The load balancer you use proxies the remote address using it's own protocol if it ever does.

@arunp1990
Copy link
Author

Ok Thanks a lot! Let me test the use-case with Load balancer and get back if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants