Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Netty UDP Server Bootstrap

Tags:

udp

netty

All TCP Server implementations with Netty 4.0 I have found use a ServerBootstrap instance.

The biggest and only difference between a server and a client in Netty is that different Bootstrap and Channel implementations are used. Please take a look at the following code:

netty docu talking about a TCP Client.


But for UDP this quote seems irrelevant?! I found examples for UDP Servers that use just Bootstrap like: 1, 2, 3

I am pretty confused by that, so my two questions are:

  • Is the Bootstrap class a correct entry point to implement a UDP Server? or may I use ServerBootstrap for it?
  • Why is there a NioServerSocketChannel.class and NioSocketChannel.class for TCP, but only one NioDatagramChannel.class (and no NioServerDatagramChannel.class) for UDP?

For Netty 3.x there was the ConnectionlessBootstrap shown here but for 4.0 I couldn't find something similar.

like image 409
Haphil Avatar asked Jun 06 '16 11:06

Haphil


1 Answers

From what I found out: Bootstrap is the correct entry point for UDP Servers in Netty 4.x

And there is no need for NioServerDatagramChannel, because UDP servers open one channel for all clients.

  • ServerBootstrap allows many client to connect via its channel. Therefore TCP has a dedicated ServerSocketChannel.
  • Bootstrap is used to create channels for single connections. Because UDP has one channel for all clients it makes sense that only the Bootstrap is requried. All clients bind to the same channel.
like image 108
Haphil Avatar answered Jan 04 '23 01:01

Haphil