Le serveur de base Netty 4.0.17 récupère un tas de ports TCP en boucle sur les fenêtres

Je cours un serveur d’écho sur Windows 7 ultime en utilisant jdk 1.7.0 (u51) 64bit.

java version "1.7.0_51" Java(TM) SE Runtime Environment (build 1.7.0_51-b13) Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode) 

Sur Linux / Mac, netstat montre que ce processus ne saisit que le port spécifié (9809 pour l’exemple pour l’écoute). Cependant, sur Windows, il saisit également un tas d’autres ports TCP en boucle (127.0.0.1).

EDIT: Le comportement est le même pour les versions netty 4.0.17.Final et la version 4.0.18.Final vient de sortir

Netstat annonce pour une exécution (le PID était 4956):

 PS C:\Users\xxxx> netstat -ano | select-ssortingng 4956 TCP 0.0.0.0:9809 0.0.0.0:0 LISTENING 4956 TCP 127.0.0.1:50682 127.0.0.1:50683 ESTABLISHED 4956 TCP 127.0.0.1:50683 127.0.0.1:50682 ESTABLISHED 4956 TCP 127.0.0.1:50684 127.0.0.1:50685 ESTABLISHED 4956 TCP 127.0.0.1:50685 127.0.0.1:50684 ESTABLISHED 4956 TCP 127.0.0.1:50686 127.0.0.1:50687 ESTABLISHED 4956 TCP 127.0.0.1:50687 127.0.0.1:50686 ESTABLISHED 4956 TCP 127.0.0.1:50688 127.0.0.1:50689 ESTABLISHED 4956 TCP 127.0.0.1:50689 127.0.0.1:50688 ESTABLISHED 4956 TCP 127.0.0.1:50690 127.0.0.1:50691 ESTABLISHED 4956 TCP 127.0.0.1:50691 127.0.0.1:50690 ESTABLISHED 4956 TCP 127.0.0.1:50692 127.0.0.1:50693 ESTABLISHED 4956 TCP 127.0.0.1:50693 127.0.0.1:50692 ESTABLISHED 4956 TCP 127.0.0.1:50694 127.0.0.1:50695 ESTABLISHED 4956 TCP 127.0.0.1:50695 127.0.0.1:50694 ESTABLISHED 4956 TCP 127.0.0.1:50696 127.0.0.1:50697 ESTABLISHED 4956 TCP 127.0.0.1:50697 127.0.0.1:50696 ESTABLISHED 4956 TCP 127.0.0.1:50698 127.0.0.1:50699 ESTABLISHED 4956 TCP 127.0.0.1:50699 127.0.0.1:50698 ESTABLISHED 4956 TCP 127.0.0.1:50700 127.0.0.1:50701 ESTABLISHED 4956 TCP 127.0.0.1:50701 127.0.0.1:50700 ESTABLISHED 4956 TCP 127.0.0.1:50702 127.0.0.1:50703 ESTABLISHED 4956 TCP 127.0.0.1:50703 127.0.0.1:50702 ESTABLISHED 4956 TCP 127.0.0.1:50704 127.0.0.1:50705 ESTABLISHED 4956 TCP 127.0.0.1:50705 127.0.0.1:50704 ESTABLISHED 4956 TCP [::]:9809 [::]:0 LISTENING 4956 

Ceux-ci n’apparaissent pas sur Linux / Mac, uniquement sous Windows. Je suppose que ceci est une sorte de mécanisme IPC sur Windows (par thread de travail peut-être), mais je voulais demander si quelqu’un pouvait clarifier cela avec autorité. Le problème est que netty / java saisit ces ports locaux exécutant toutes les autres applications essayant de se connecter à ces ports (principalement les serveurs de développement, les débogueurs allouant des ports élevés aléatoires) échouent avec un message d’erreur de type refusée. Je travaille surtout sur linux / mac, alors je me demande si j’ai manqué un redmondisme évident 🙂

Le code du serveur d’écho est donné ci-dessous: (je l’ai réduit à un serveur de base pour tester)

 package test; import io.netty.bootstrap.ServerBootstrap; import io.netty.buffer.ByteBuf; import io.netty.channel.Channel; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInitializer; import io.netty.channel.SimpleChannelInboundHandler; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel; public class TestServer extends ChannelInitializer{ private int port = 9809; public TestServer(int port) { this.port = port; } public void run() throws Exception { NioEventLoopGroup pool = new NioEventLoopGroup(); try { ServerBootstrap bootstrap = new ServerBootstrap(); Channel c = bootstrap.group(pool).channel(NioServerSocketChannel.class).childHandler(this).bind(port).sync().channel(); c.closeFuture().sync(); } finally { pool.shutdownGracefully(); } } /** * @param args */ public static void main(Ssortingng[] args) throws Exception { int port = 9809; TestServer server = new TestServer(port); server.run(); } @Override protected void initChannel(SocketChannel channel) throws Exception { channel.pipeline().addLast("handler", new Handler()); } private class Handler extends SimpleChannelInboundHandler { @Override protected void channelRead0(ChannelHandlerContext ctx, Object obj) throws Exception { ByteBuf buf = (ByteBuf)obj; ctx.writeAndFlush(buf.retain()); } } } 

Je pense que je me souviens de la façon dont Java NIO fonctionne sur Windows, donc nous ne pouvons rien y faire dans Netty.