users@grizzly.java.net

[spam] Re: Many extra connections when running WebSocket server or client.

From: Oleksiy Stashok <oleksiy.stashok_at_oracle.com>
Date: Thu, 09 May 2013 15:07:13 -0700

Hi,

it's Windows specific Java NIO Selector behavior, when you create a
Selector it creates loopback connection (2 TCP connections).
We can do nothing about that, it's how Java NIO works on Windows.

Thanks.

WBR,
Alexey.

On 09.05.13 14:05, Weiqi Gao wrote:
> Hi,
>
> When I start a simple HttpServer using Grizzly, like this:
>
> import org.glassfish.grizzly.http.server.HttpServer;
> import java.io.IOException;
>
> public class JustHttpServerMain {
> public static void main(String[] args) throws IOException {
> HttpServer server = HttpServer.createSimpleServer(".", 8080);
> server.start();
> System.in.read();
> }
> }
>
> I see the Java process listening on port 8080, which is what I expect,
> and 8 additional connections that the process makes to itself. Here's
> the output of "netstat -anto | grep 9536" (where 9536 is the pid):
>
> $ netstat -anto | grep 9536
> TCP 0.0.0.0:8080 0.0.0.0:0 LISTENING 9536 InHost
> TCP 127.0.0.1:49339 127.0.0.1:49340 ESTABLISHED 9536
> InHost
> TCP 127.0.0.1:49340 127.0.0.1:49339 ESTABLISHED 9536
> InHost
> TCP 127.0.0.1:49341 127.0.0.1:49342 ESTABLISHED 9536
> InHost
> TCP 127.0.0.1:49342 127.0.0.1:49341 ESTABLISHED 9536
> InHost
> TCP 127.0.0.1:49343 127.0.0.1:49344 ESTABLISHED 9536
> InHost
> TCP 127.0.0.1:49344 127.0.0.1:49343 ESTABLISHED 9536
> InHost
> TCP 127.0.0.1:49345 127.0.0.1:49346 ESTABLISHED 9536
> InHost
> TCP 127.0.0.1:49346 127.0.0.1:49345 ESTABLISHED 9536
> InHost
> TCP 127.0.0.1:49347 127.0.0.1:49348 ESTABLISHED 9536
> InHost
> TCP 127.0.0.1:49348 127.0.0.1:49347 ESTABLISHED 9536
> InHost
> TCP 127.0.0.1:49349 127.0.0.1:49350 ESTABLISHED 9536
> InHost
> TCP 127.0.0.1:49350 127.0.0.1:49349 ESTABLISHED 9536
> InHost
> TCP 127.0.0.1:49351 127.0.0.1:49352 ESTABLISHED 9536
> InHost
> TCP 127.0.0.1:49352 127.0.0.1:49351 ESTABLISHED 9536
> InHost
> TCP 127.0.0.1:49353 127.0.0.1:49355 ESTABLISHED 9536
> InHost
> TCP 127.0.0.1:49355 127.0.0.1:49353 ESTABLISHED 9536
> InHost
> TCP [::]:8080 [::]:0 LISTENING 9536 InHost
>
> This is on a Windows 7 Pro SP1 environment with 64-bit Oracle JDK
> 1.7.0_21.
>
> Am I the only one who gets the extra connections? If this is
> something that is known, is there an explanation (or a fix) for it?
>
> Thanks,
> --
> Weiqi Gao
> weiqigao_at_gmail.com
> http://weiqigao.blogspot.com/