Java Forum / General / February 2006
sockets - setReceiveBufferSize doesn't work...
chrisrocker90@yahoo.com - 07 Feb 2006 17:53 GMT I'm trying to set the receive (and send) size on a socket buffer. However, it doesn't seem to work. When I compare it with the advertised window size in the tcp header, there is no correlation. I used a packet sniffer to read the outbound TCP header window size.
Heres the code:
destSocket = new Socket(destHost, destPort); destSocket.setSendBufferSize(256); destSocket.setReceiveBufferSize(256); System.out.println(destSocket.getReceiveBufferSize()); System.out.println(destSocket.getSendBufferSize());
Reprinting the buffers sizes show the set method works; but as I said, there is no change in the window size. I've tried several different values, but none seem to take.
Am I misunderstanding the purpose of the socket buffer, or is it just not working?
- Chris
Gordon Beaton - 07 Feb 2006 18:10 GMT > I'm trying to set the receive (and send) size on a socket buffer. > However, it doesn't seem to work. When I compare it with the [quoted text clipped - 8 lines] > System.out.println(destSocket.getReceiveBufferSize()); > System.out.println(destSocket.getSendBufferSize()); Depending on the platform, it may be necessary to set the buffer sizes before connecting, which you aren't doing here. Try creating an unconnected Socket and setting the values before calling connect().
Also the value is only a hint and some platforms may use a larger value than the one you suggest.
/gordon
 Signature [ do not email me copies of your followups ] g o r d o n + n e w s @ b a l d e r 1 3 . s e
chrisrocker90@yahoo.com - 07 Feb 2006 19:52 GMT Ok, I tried this:
destSocket = new Socket();
InetSocketAddress sa = new InetSocketAddress(destHost, destPort); destSocket.setSendBufferSize(16384); destSocket.setReceiveBufferSize(16384);
System.out.println("destHost: " + destHost + ", destPort: " + destPort); System.out.println(destSocket.getReceiveBufferSize()); System.out.println(destSocket.getSendBufferSize());
destSocket.connect(sa);
This output is this:
4000 3784 127.0.0.1 destHost: 127.0.0.1, destPort: 3784 16384 16384
But - the window size is still around 64K. The OS is Win2K. I guess this is one of the operating systems which ignores the socket buffer sizing. Is there a workaround to this, or a patch to the jvm or os, or anything? Or should I write it in C (which I'm not that familiar with, but if it works, well, it works).
Chris
EJP - 08 Feb 2006 00:44 GMT Chris,
Why are you using such small numbers? 256 and 16384? 64k would be more like it these days.
chrisrocker90@yahoo.com - 08 Feb 2006 15:05 GMT EJP,
The numbers are abitrary at this point - I'm just trying to see if it works, first. I've also tried numbers larger than 64k, with no luck. What I'm really trying to do is use a TCP proxy to calculate the bandwidth * delay product such that the receive buffer is appropriate to the connection. That way, on a long fat pipe a large window could be used, but on a thin pipe a much smaller window could be used. I'm getting ready to quit on it for now, or move to C at the least, which I also have my doubts about working on the winsock API.
- Chris
EJP - 08 Feb 2006 23:37 GMT > EJP, > [quoted text clipped - 6 lines] > getting ready to quit on it for now, or move to C at the least, which I > also have my doubts about working on the winsock API. OK. The Windows default is 8k but this can be changed via a registry setting called TcpWindowSize which may have happened in your case.
The platform is free to adjust the size you supply to setSendBufferSize()/setReceiveBufferSize(), both upwards and downwards, so your test with 256 is never going to work as expected because 256 is far too small for any platform I am aware of.
The maximum is 64k-1 unless you use window scaling, which implies that you have to set the buffer sizes prior to calling connect() for a client, or on the ServerSocket for a server.
chrisrocker90@yahoo.com - 09 Feb 2006 19:54 GMT EJP,
Still no luck. I set the relevant registy entries as follows:
GlobalMaxTcpWindowSize: 65535 TcpWindowSize: 32760 TCP1323Opts: 1 (Supports scaling)
My program sets all buffer sizes on all sockets to 16834. It's done before establishing a connection for them. It's a proxy server, so there are 3 sockets, i.e. the server socket, the socket it spawns, and the connection to the remote host.
However, despite all this, the packet sniffer shows the windows size to be 32760. The initial syn opt shows that the windows scaling option is 0, i.e, don't scale the value.
Have you gotten this kind of thing to work on win2k before? Could it be the Winsock implmentation? Also, have your worked on bandwidth * delay and setting the buffer size? If so, how did it work out? I noticed there is a lot more work being done on Linux in this area, but I'm trying to make this cross-platform. Thanks for any advice you can offer. I'm ready to give up on this one.
- Chris
Gordon Beaton - 09 Feb 2006 20:02 GMT > My program sets all buffer sizes on all sockets to 16834. It's done > before establishing a connection for them. It's a proxy server, so > there are 3 sockets, i.e. the server socket, the socket it spawns, and > the connection to the remote host. Note that you must set the buffer sizes for the *ServerSocket* in order for this to have an effect on the Sockets that are created from it in response to arriving connections. This is because the Sockets will inherit their values from the ServerSocket, and you have no other chance to set them before they are connected.
/gordon
 Signature [ do not email me copies of your followups ] g o r d o n + n e w s @ b a l d e r 1 3 . s e
chrisrocker90@yahoo.com - 09 Feb 2006 20:28 GMT Unfortunately, I'm already doing that
public final static int BUFF_SIZE = 16834;
mainSocket = new ServerSocket(); mainSocket.setReceiveBufferSize(BUFF_SIZE); InetSocketAddress serverPort = new InetSocketAddress ( SERVER_PORT ); mainSocket.bind(serverPort); System.out.println("mainSocket.getReceiveBufferSize(): " + mainSocket.getReceiveBufferSize()); output is:
mainSocket.getReceiveBufferSize(): 16834
- Chris
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|