×
Namespaces

Variants
Actions
Revision as of 06:12, 12 August 2011 by hamishwillee (Talk | contribs)

Set TCP Window Size

From Nokia Developer Wiki
Jump to: navigation, search

Contents

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));
 
#ifdef CLIENT_CODE
connect(sock, (struct sockaddr *) &address, sizeof(address));
#endif
 
#ifdef SERVER_CODE
listen(sock, 5);
 
accept(sock, NULL, NULL);
#endif

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.


References


Links

90 page views in the last 30 days.
×