S
Steve Schaeffer
Hi all,
I'm trying to specify a port number for the client side of a TCP connection
and I'm not having success. According to what I've read in the sdk 1.4.2_02
docs this should be the way to do it (and this parallels what works in C):
socket = new Socket();
socket.setReuseAddress(true);
socket.bind(new InetSocketAddress(InetAddress.getLocalHost(), localPort));
socket.connect(new InetSocketAddress(serverAddress, serverPort));
I don't get any errors, but I also don't get the desired result. In Windows
I get the correct port number assigned the first time but the reuseaddr is
ignored and I can't re-connect until after the TIME_WAIT period expires. In
Linux, I don't even get the specified local port asigned and instead I get
the next ephemeral port assigned, as though I did not specify a port or
specified port 0.
I also tried doing it this way, even though I didn't expect it to work from
reading the docs:
socket = new Socket(serverAddress, serverPort, InetAddress.getLocalHost(),
localPort);
I've searched the web and not found any contrary information, nor did I find
any examples that claim to work. Is this broken in Java?
Any information would be appreciated.
Thanks.
I'm trying to specify a port number for the client side of a TCP connection
and I'm not having success. According to what I've read in the sdk 1.4.2_02
docs this should be the way to do it (and this parallels what works in C):
socket = new Socket();
socket.setReuseAddress(true);
socket.bind(new InetSocketAddress(InetAddress.getLocalHost(), localPort));
socket.connect(new InetSocketAddress(serverAddress, serverPort));
I don't get any errors, but I also don't get the desired result. In Windows
I get the correct port number assigned the first time but the reuseaddr is
ignored and I can't re-connect until after the TIME_WAIT period expires. In
Linux, I don't even get the specified local port asigned and instead I get
the next ephemeral port assigned, as though I did not specify a port or
specified port 0.
I also tried doing it this way, even though I didn't expect it to work from
reading the docs:
socket = new Socket(serverAddress, serverPort, InetAddress.getLocalHost(),
localPort);
I've searched the web and not found any contrary information, nor did I find
any examples that claim to work. Is this broken in Java?
Any information would be appreciated.
Thanks.