Question about UDP send

Trustin Lee (이희승) trustin at gmail.com
Thu Sep 24 22:02:00 EDT 2009


Hi YJ,

On Mon, Sep 21, 2009 at 11:57 AM, Y. J. Chun <monac3 at gmail.com> wrote:
> Hello.
>
> My server receives UDP packet and send reply back to the client.
> It is working well but I want to specify local address and port to
> bind when sending the UDP packet.
> Currently i can set only the remote address, and not local address to
> bind. Is it possible in netty?

If you want to send a UDP packet from the different local address than
the current channel's local address, I think you need to create a new
UDP channel and bind the new channel to the local address you desire
to bind to.  As far as I know, there's no way to specify a local
address when sending a UDP packet in general (e.g. JDK)

> Another side question is, to send udp packet you always have to set
> remote address for write method
> but if the udp packet is to be sent using same channel that used to
> receive packet,
> (eg. send using the channel passed from messageReceived()), why not
> remote address to be set as the channel's remote address by default?

Channel.write() can be called from any thread concurrently.
Therefore, there is no way to determine what was the previous remote
address reliably when packets are received from multiple remote peers.

HTH

— Trustin Lee, http://gleamynode.net/



More information about the netty-users mailing list