DasyneServer, Initialization



setSegmentSize
setMaxClients
enableUDP
setFlushLimit
setEDCLimit
setMessageLimit
setFlushPeriod
setEDCPeriod
unusedBytes
initialize
getErrMsg

The DasyneServer class handles all server-side data synchronization. Dasyne is built on top of DyConnect, and DyConnect's startup function needs to be called before using it.

DasyneServer initialization functions:


bool setSegmentSize(uint16_t segmentSize, uint16_t speckSize);

Set the size of each segment and speck in bytes. speckSize must divide evenly into segmentSize to prevent wasted space in the data map.

segmentSize can have a minimum value of DY_MIN_SEGMENTSIZE. The larger your segment size, the faster clients will be able to scan the data map for errors. (One CRC value covers that much more space.) On the other hand, if a synchronization error is detected the entire segment will be sent, which can be wasteful if your segment size is very large. Generally, you would only increase the segment size if you have a very large amount of data to synchronize.

The default segment size is 1024 bytes, and the default speck size is 4 bytes. If you aren't sure what to use here, these are sensible values for most games.

If you have no idea what any of this means, be sure to read the Dasyne Overview.

Returns false on errors, and sets errMsg with a description of the problem.


bool setMaxClients(int numClients);

Set the maximum number of clients that can connect to the server.

Returns false on errors, and sets errMsg with a description of the problem.


bool enableUDP(uint16_t portNumber);

enableUDP activates the UDP subsystem on the specified portNumber. Data flushes will be sent over UDP if it's enabled, and the sendUDP function will be activated. It's recommended to enable UDP to reduce lag.

Returns false on errors, and sets errMsg with a description of the problem.


void setFlushLimit(uint16_t newLimit);

Sets the bandwidth data flush mechanism will use, in bytes per second. This is on a per-client basis. If you have 5 clients connected, and the flush limit is 1024, the server will upload up to 5 kilobytes of flush data per second.

The default value is 1024 bytes per second.


void setEDCLimit(uint16_t newLimit);

Sets the bandwidth the EDC mechanism will use, in bytes per second. If a synchronization error is detected between the server and a client, this is the maximum amount of bandwidth that will be used to transfer the segment to the client. This is on a per-client basis. If you have five clients and the EDC limit is 1024, the server will send up to 5 kilobytes of segment data per second.

The default value is 512 bytes per second.


void setMessageLimit(uint16_t newLimit);

If you plan on using sendTCP, you can tell Dasyne about it here. newLimit is the number of bytes per second that you think you'll be sending (on average). This doesn't have to be an exact number, it's just a rough estimate that helps the DasyneServer estimate congestion.

sendTCP and DasyneServer share a TCP/IP connection. Dasyne will stop sending data if it notices a lot of unsent bytes in the TCP send buffer. If you set newLimit to 2 kilobytes, the send buffer will be allowed to grow an extra 2 kilobytes before Dasyne stops sending.


bool setFlushPeriod(uint16_t newPeriod);

Sets the time in milliseconds that the server will wait before sending data flushes. If newPeriod is 100, then the server will send up to 10 data flushes per second. The default value is 100 milliseconds.

newPeriod can be between 1 and 1000 milliseconds.

Returns false on errors, and sets errMsg with a description of the problem.


bool setEDCPeriod(uint16_t newPeriod);

When a mismatched segment is sent to a client, it may need to be split up into smaller messages. The EDC period defines the interval at which the messages will be sent. The default value is 500 milliseconds, or up to 2 messages per second. This period is required to stop the EDC mechanism from filling the TCP send buffer with large amounts of segment data and introducing lag.

newPeriod can be between 1 and 1000 milliseconds. If you set the period to be very small, you end up with lots of little segment messages, which are less efficient than sending larger messages less frequently.

Returns false on errors, and sets errMsg with a description of the problem.


uint32_t unusedBytes(void);

Returns the number of skipped bytes in the data map. Call unusedBytes after you've declared all your SyncData and SyncArray variables to see how many bytes weren't used. Ideally, this number should be zero.

You can reduce the number of unused bytes by declaring your variables in a different order, or by changing your speck size. See the Dasyne Overview for more.


bool initialize(int portNumber);

Once everything's configured the way you like, initialize this server. It will start listening for TCP/IP connections from clients on the specified portNumber. When you call initialize the server's data map is created, and it's size is based on the SyncData and SyncArray objects you've created. You will now be able to access your SyncData and SyncArray variables.

(At this point, you will no longer be able to create any new SyncData or SyncArray objects.)

Initialize needs to be called before you start using the DasyneServer networking functions.

Returns false on errors, and sets errMsg with a description of the problem.


string getErrMsg(void);

Return a description of the most recent error for this DasyneServer.