Skip to main content

imp.setsendbuffersize(newSize)

Attempts to set the size of the imp’s TCP send window for server communications

Availability

Device (from impOS™ 27)

Parameters

Name Type Description
newSize Integer The requested TCP send window size in bytes

Returns

Integer — the previous size of the imp’s TCP send window in bytes

Description

The default network buffer size (3KB) should be fine for most purposes, but when streaming data from the imp, a larger buffer can enable higher bandwidth. For more information on choosing an optimal buffer size, see Wikipedia’s article on TCP tuning.

The maximum bandwidth achievable is constrained by the window size divided by the round-trip time (RTT). If your imp’s ‘ping time’ to our servers is 100ms, and the send buffer is 3KB (the default), then the theoretical maximum data rate is 3KB/100ms or 30KB/s.

Requesting a larger window using this call can improve that maximum data rate, though naturally it reduces the amount of memory in the imp usable for everything else, including Squirrel objects.

The return value from the call is the previous size of the send buffer in bytes.

Note that this is a request for a particular buffer size. The imp imposes an upper bound on the size of the send buffer, currently around 30KB. The imp may also optimize the precise size of the send buffer, but it will be at least as big as requested, up to the upper bound.

The new size of the buffer will be preserved across a Squirrel reload provided no reconnection takes place — for example, if a send policy of RETURN_ON_ERROR is in place, the imp is disconnected and calls server.restart().

While the imp is connected, this method can only increase the size of the send buffer from the default, not reduce it. However, if the imp is disconnected, the size of the buffer can be increased or decreased — but never below the default value (3KB). For example, if the buffer size is increased to 5KB, it can subsequently be reduced to any value between 5KB and 3KB, but not to, say, 2KB. If the buffer size is not increased from the default, it cannot be subsequently reduced in size.