NetworkEngine, Initialization



setTimeout
setMaxConnections
setBufferSize
limitReceiveRate
initialize
getErrMsg

The following functions are used to configure and initialize a NetworkEngine object. All of the configuration functions here need to be called before initialize.


bool setTimeout(int numSeconds);

Set the number of seconds to wait before disconnecting an idle client. If numSeconds is zero or negative, the auto-disconnect will be disabled. The default value is 60 seconds.

Returns false on failure, and stores a description of the problem in errMsg.


bool setMaxConnections(int numConnections);

Set the maximum number of TCP/IP connections that the NetworkEngine can handle at one time. Each connection will be given it's own thread for sending and receiving data. The default value is 8 connections.

Returns false on failure, and stores a description of the problem in errMsg.


bool setBufferSize(int newSize);

Modify the size of each thread's send and receive buffers. You can set the buffer size to be between 128 and 32767 bytes. The default value is 4096. Larger buffers can result in more bandwidth, but require more CPU cycles. You may wish to increase the buffer size if your transfer rates seem artificially low.

Returns false on failure, and stores a description of the problem in errMsg.


bool limitReceiveRate(long int kBps)

Limits the amount of data each thread can read from the TCP/IP buffers. kBps should be between 0 and 2097152 kilobytes per second. A value of zero allows an unlimited receive rate. (zero is the default value). limitReceiveRate is intended as a security measure to prevent attackers from flooding your receive buffers and exhausting the system RAM.

It should not be used as a way to reduce transfer rates during your program's normal operation, as this can introduce lag. The TCP/IP system is designed to only accept more data after X number of kilobytes have been received by the program. If X is 32, and you limit the receive rate to 1 kBps, then you will introduce 32 seconds of lag before the client can send more data. If you need to limit transfer rates, you might be better off reducing the amount of data clients send.

As a general rule, the receive limit should be higher than the expected transfer rate, but low enough to prevent an attacker from adding to your receive buffers faster than you can read from them.

Returns false on failure, and stores a description of the problem in errMsg.


bool initialize(void);

Initialize the NetworkEngine to begin TCP/IP networking. It returns false on failure, and stores a description of the problem in errMsg.

Note: All of the above configuration routines must be called before initialize.


string getErrMsg(void);

Returns a description of the most recent error for this NetworkEngine.