Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Set TCP Window Size

From Wiki
Jump to: navigation, search
Article Metadata
Created: vvsnaresh (12 Sep 2007)
Last edited: hamishwillee (27 Jul 2012)


What is a TCP Window ?

A TCP window is the amount of outstanding data (unacknowledged by the receiver) a sender can send on a particular connection before it gets an acknowledgment back from the receiver, that has received some of the data.

The primary reason for the TCP window is congestion control. The TCP window throttles down the transmission speed to a level where congestion and data loss do not occur.

Considering the importance of TCP Window, one should make sure that the two ends correctly negotiate the Window Size before making a connection. The main reason for establishing a Windows Size is that there are only 16 bits reserved for the window size in the TCP header, with a maximum window sizes of 64 KB.

To work around this limitation, the TCP window scale option was introduced. So, if a window size greater than 64 KB is to be established, it must be done at connection set-up time.

Setting the TCP Window Size

The following Open C code snippet shows how to set the TCP Window size on a client and a server.

int window_size = 128 * 1024;	/* 128 kilobytes */
sock = socket(AF_INET, SOCK_STREAM, 0);
/* Both the setsockopt() calls should be before the connect()/accept() */
setsockopt(sock, SOL_SOCKET, SO_SNDBUF,
(char *) &window_size, sizeof(window_size));
setsockopt(sock, SOL_SOCKET, SO_RCVBUF,
(char *) &window_size, sizeof(window_size));
connect(sock, (struct sockaddr *) &address, sizeof(address));
listen(sock, 5);
accept(sock, NULL, NULL);

The setsockopt() function provides an application program with the means to control socket behaviour. The required header file for this is sys/socket.h. In the above code, the setsockopt() calls must come before the connect() or accept() calls.



This page was last modified on 27 July 2012, at 04:15.
633 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.