





Dwango API Specification
Beta Version 0.2

January 4, 1996

Interactive Visual Systems, Corporation
9525 Katy Freeway, #316
Houston, TX 77079
(713) 467-8865

IVS, Corp. Confidential

This document contains Confidential Information 
subject to the Non-Disclosure Agreement between 
IVS, Corp. and the recipient of this document.


Programmer's Guide
Welcome to the Dwango Application Programming Interface (DAPI), Beta release 0.2. Dapi is a simple 
interface for exchanging messages between game players who are playing on a Dwango multiplayer game 
server.
Multiplayer Communication
Dapi provides three ways to send a message to another player-node:
1.  dapiSend() is the fastest, giving the game the highest bandwidth and consuming the least 
processing overhead. dapiSend() sends unacknowledged, unvalidated messages, so there is some 
chance that a message could be lost or mangled. Dapi guarantees that messages arrive in the 
same sequence as they were sent. Use dapiSend() if your game tolerates lost messages and either 
your game does its own message validation or your game tolerates corrupted messages.
2.  dapiSendWithCRC() sends unacknowledged messages, but computes a sixteen-bit CRC on the 
message, "guaranteeing" that the message arrives unchanged. If Dapi detects a CRC error in the 
message, Dapi discards the message. Dapi guarantees that messages arrive in the same sequence 
as they were sent.
dapiSendWithCRC() provides almost as much bandwidth as dapiSend() but dapiSendWithCRC() 
incurs the processing overhead of computing the CRC on both the sender and receiver player-
nodes. dapiSendWithCRC()'s per-message overhead is three bytes more than dapiSend(). Use 
dapiSendWithCRC() if your game tolerates lost messages but requires messages to arrive 
uncorrupted.
3. dapiSendAcked() is the most reliable method of getting a message to another player-node, but is 
also the most expensive method in bandwidth consumption, memory consumption, and 
processing overhead. dapiSendAcked() guarantees message delivery, integrity, and sequence 
because Dapi keeps sending a message until it gets an acknowledgment for the message. 
Use dapiSendAcked() sparingly! Use dapiSendAcked() if you want reliable message exchange 
and you have a small bandwidth requirement for reliable message exchange. Fast-playing games 
should use dapiSendAcked() infrequently.
Dapi Routines
Dapi contains the following routines:
dapiInit()	Initialize Dapi.
dapiThisNode()	Get the player's Dapi node number.
dapiNodeName()	Get a player-node's ASCII name.
dapiSend()	Send a message to one other player-node; no guarantee on message 
delivery or integrity.
dapiSendWithCRC()	Send a message to one other player-node; the message is guaranteed to 
be uncorrupted, but its delivery is not guaranteed.
dapiSendAcked ()	Send a message to one other player-node; the message is guaranteed to 
be delivered, uncorrupted, and in the sequence sent.
dapiBroadcast()	Send one message to all other player-nodes; no guarantee on message 
delivery or integrity.
dapiBroadcastWithCRC()	Send one message to all other player-nodes the message is guaranteed to 
be uncorrupted, but its delivery is not guaranteed.
dapiSendScore()	Send a player's score to the Dwango server.
dapiRecv()	Receive a message from another player-node.
dapiClose()	Close Dapi.
dapiErrorString()	Translate a Dapi return error number into an ASCII string.

Sample code is provided for each Dapi routine (init.c contains the dapiInit() example, send.c contains the 
dapiSend() example, etc.). A sample "game" is provided that calls all Dapi routines: gamesamp.c and 
gamesamp.exe.
Recommended Message Rates
Dwango recommends that you send a few small messages each second! Modem bandwidth is typically the 
bottleneck in multiplayer games, so the fewer the messages and the smaller the messages the better. When 
possible, call dapiBroadcast() to send one message to all other players rather than calling dapiSend() once 
for each other player because dapiBroadcast() saves bandwidth on the sending side. Dwango's 
recommended message rate and size table is "To Be Done".
Compiling and linking the samples
Dapi Beta 0.2 works with DOS-based games. Dapi for Window95 will be available soon. Sample code 
should be compiled with Watcom 10.0 or later and linked with dapi.lib and the Greenleaf CommLib 
gclfr32.lib version 5.1 or later (version 5.0 misbehaves). A Watcom makefile is provided for making each 
Dapi sample .exe.
Installation & Testing
Create a Dapi directory on each game PC and unzip Dapi.zip into that directory. The minimum software 
needed to run gamesamp.exe is dapi.cfg and dos4gw.exe.
In this Beta release of Dapi, manually edit the Dapi configuration file dapi.cfg on each PC. The Dapi.cfg 
file for a two-player game, player-zero looks like:
this_node: 0 
num_nodes: 2
speed: 19200
com:  0
node: 0  0 PlayerZero
node: 1  1 PlayerOne

The fields of Dapi.cfg are:
this_node:	The 0-based player-node number, different on each PC.
num_nodes: 	The 1-based number of player-nodes.
speed: 	The baud rate (best to use 19200).
com:	Use 0 for Com1. Use 1 for Com2.
node:	One of these entries for each player-node. Make sure the 
two numbers on each line are the same and that no two 
nodes are the same.

In this Beta release of Dapi, Dwango supports two methods of testing Dapi:
1.  Direct connection between two PCs.
a)	Establish a null-modem connection between two PCs, PC-zero and PC-one.
i)	Connect a null-modem-cable from one PC's com port to the other PC's com port, using 
Com1 or Com2 on each PC.
ii)	Run a terminal program like PCPlus or Windows3.1 Terminal or Win95 HyperTerminal 
on each PC, choosing "direct connection"; verify that the two PC's talk to each other at 
a baud rate of 19200.
b)	Verify that Dapi works between the two PCs.
i)	Edit the dapi.cfg on each PC, setting "this_node: 0" on PC-zero and "this_node: 1" on 
PC-one. Set "com: 0" if using Com1 or set "com: 1" if using Com2.
ii)	On PC-zero, run recv.exe; on PC-one, run send.exe a couple of times; PC-zero should 
display "dapiRecv() from 1..".
iii)	On PC-one, run recv.exe; on PC-zero, run send.exe a couple of times; PC-one should 
display "dapiRecv() from 0.."
iv)	Run gamesamp.exe on each PC; on PC-zero, type "1 Hello One!" then "Alive"; on PC-
one, type "0 Hello Zero!" then "Me too". Each message should appear on the other PC's 
screen.
c)	Test a two-player version of your game.
2.	Two or more PCs connected to a Dapi game router PC either directly or via modem. Contact 
IVS/Dwango for details.
DAPI Programmer's Reference
The following pages specify each Dapi routine.
int dapiInit (char *szConfigFileName);
Return Value
dapiInit() returns the number of player-nodes in the current game. The 
number of players returned is one-based.
If there is an error, then dapiInit() returns a negative DAPI_ error.
Parameter
szConfigFileName is name of the Dapi configuration file to read. If 
szConfigFileName is NULL, then Dapi reads the default configuration file 
"dapi.cfg". 
Description
dapiInit() initializes Dapi and returns the number of player-nodes in the 
current game. Call dapiInit() before any other calls to Dapi, or the other calls 
will return DAPI_NotInited. 
When the Dwango client launches a game, the client creates the dapi.cfg file. 
Pass NULL to dapiInit() so that Dapi reads the client-created dapi.cfg. Use 
the parameter szConfigFileName only during standalone testing.
See Also
	dapiThisNode()	dapiNodeName()	dapiSend()
	dapiSendWithCRC()	dapiSendAcked()	dapiSendScore()
	dapiBroadcast()	dapiBroadcastWithCRC()	dapiRecv()
	dapiClose()
Example
#include <stdio.h>
#include "dapi.h"

void main()
{
  int iPlayers;

    iPlayers = dapiInit(NULL);

    if (iPlayers <= 0)
    {
        printf("dapiInit() error: %s\n", dapiErrorString(iPlayers));
        return;
    }

    printf ("\nNumber of player-nodes: %d\n", iPlayers);

    dapiClose();
    return;

} // end-main()---------------- dapiInit() sample -------------------
int dapiThisNode (void);
Return Value
dapiThisNode() returns a zero-based node number that is the player-node of 
the calling application. If there is an error, then dapiThisNode() returns a 
negative DAPI_ error.
Parameters
None.
Description
Call dapiThisNode() to get the player's Dapi node number. Note that player-
nodes are zero-based, while the number of nodes that dapiInit() returns is 
one-based. 
See Also
	dapiInit()	dapiNodeName()	dapiSend()
	dapiSendWithCRC()	dapiSendAcked()	dapiSendScore()
	dapiBroadcast()	dapiRecv()	dapiClose()
	dapiBroadcastWithCRC()
Example
#include <stdio.h>
#include "dapi.h"

void main()
{
  int iPlayers, iThisPlayerID;

    iPlayers = dapiInit(NULL);
    if (iPlayers <= 0)
    {
        printf("dapiInit() error: %s\n", dapiErrorString(iPlayers)); 
        return;
    }
    printf ("\nNumber of player-nodes: %d\n", iPlayers);

    iThisPlayerID = dapiThisNode();

    if (iThisPlayerID < 0)
    {
        printf("dapiThisNode() error: %s\n", 
               dapiErrorString(iThisPlayerID));
        return;
    }

    printf("This player-node ID:    %d\n", iThisPlayerID);

    dapiClose();
    return;
} // end-main()-------------- dapiThisNode() sample -----------------

// In a three player game, the output for the first player:
Number of player-nodes: 3
This player-node ID:    0

// The output for the second player:
Number of player-nodes: 3
This player-node ID:    1

// The output for the third player:
Number of player-nodes: 3
This player-node ID:    2
int dapiNodeName(int iPlayerNode, char *szName)
Return Value
When successful, dapiNodeName() returns DAPI_NoError. When 
unsuccessful, dapiThisNode() returns a negative DAPI_ error.
Parameters
iPlayerNode	is the player's Dapi node number, ranging from zero to (the 
number of players returned by dapiInit() minus one). 
szName	points to a character array that must be at least 
(DAPI_NODE_NAME_CHARS + 1) characters in length. 
Dapi copies the player-node's name to szName.
Description
Call dapiNodeName() to get a player's ASCII name.
See Also
	dapiInit()	dapiThisNode()	dapiSend()
	dapiSendWithCRC()	dapiSendAcked()	dapiSendScore()
	dapiBroadcast()	dapiRecv()	dapiClose()
	dapiBroadcastWithCRC()
Example
#include <stdio.h>
#include "dapi.h"
void main()
{
  int iPlayers, iErr, iThisPlayerID, i;
  char szName [DAPI_NODE_NAME_CHARS + 1];  // 1 for null-terminator.

    iPlayers = dapiInit(NULL);
    if (iPlayers <= 0)
    {
        printf("dapiInit() error: %s\n", dapiErrorString(iPlayers));
        return;
    }
    printf ("\nNumber of player-nodes: %d\n", iPlayers);

    iThisPlayerID = dapiThisNode();
    if (iThisPlayerID < 0)
    {
        printf("dapiThisNode() error: %s\n", 
               dapiErrorString(iThisPlayerID));
        return;
    }
    printf("This player-node ID:    %d\n", iThisPlayerID);

    for (i = 0; i < iPlayers; ++i)
    {
        iErr = dapiNodeName(i, szName);
        if (iErr < 0)
        {
            printf("dapiNodeName() error: %s\n", dapiErrorString(iErr));
        }
        else
        {           
            printf("Player-node %d name: %s\n", i, szName);
        }
    }
    dapiClose();
    return;
} // end-main()--------- dapiNodeName() example -----------------------
int dapiSend (int iDestPlayerNode, unsigned char *pMsg, int iLength);
Return Value
When successful, dapiSend() returns DAPI_NoError. When unsuccessful, 
dapiSend() returns a negative DAPI_ error.
Parameters
iPlayerNode	is the message's zero-based destination.
pMsg	points to the message.
iLength	is the number of bytes in the message.
Description
Call dapiSend() to send messages to other individual Dapi player-nodes. 
In order to provide the fastest possible message delivery, dapiSend() does not 
guarantee delivery of the message or integrity of the message. Lost and/or 
corrupt messages are possible due to modem line noise and exceeding 
recommended bandwidth. dapiSend() guarantees the delivery order of 
messages.
Do not send messages to dapiThisNode(); attempts to do so result in the error 
DAPI_NoLoopBack.
Call dapiBroadcast() to send one message to all other player-nodes. It is 
much better to call dapiBroadcast() once than to call dapiSend() for each 
other player because dapiBroadcast() reduces bandwidth consumption.
See Also
	dapiInit()	dapiThisNode()	dapiNodeName()
	dapiSendWithCRC()	dapiSendAcked()	dapiSendScore()
	dapiBroadcast()	dapiRecv()	dapiClose()
	dapiBroadcastWithCRC()
Example
#include <stdio.h>
#include "dapi.h"

#define BUF_BYTES   3
unsigned char Buf [BUF_BYTES] = {0xFF, 0xA5, 0x5E};

void main()
{
  int iPlayers, iThisPlayerID, i, iErr;

    iPlayers = dapiInit(NULL);

    if (iPlayers <= 0)
    {
        printf("dapiInit() error: %s\n", dapiErrorString(iPlayers)); 
        return;
    }
    printf ("\nNumber of player-nodes: %d\n", iPlayers);

    iThisPlayerID = dapiThisNode();

    





    //---------------------------------------------------------
    // Make sure dapiThisNode() worked (iThisPlayerID is >= 0)
    // and that there are two or more players in the game.
    //---------------------------------------------------------
    if ((iThisPlayerID < 0) || (iPlayers < 2))
    {
        printf("dapiThisNode() error: %s\n", 
                dapiErrorString(iThisPlayerID));
        return;
    }

    for (i = 0; i < iPlayers; ++i)
    {
        //----------------------------------------------------
        // Send a short message to each of the other players,
        // changing the message slightly for each player.
        //----------------------------------------------------
        if (i != iThisPlayerID)
        {
            Buf [0] = i;
            iErr = dapiSend (i, Buf, BUF_BYTES);

            printf("dapiSend(to %d): %s\n", i, dapiErrorString(iErr));
        }
    }
    dapiClose();
    return;

} // end-main()--------- dapiSend() example -----------------------

int dapiSendWithCRC (int iDestPlayerNode, unsigned char *pMsg, int iLength);
Return Value
When successful, dapiSendWithCRC() returns DAPI_NoError. When 
unsuccessful, dapiSendWithCRC() returns a negative DAPI_ error.
Parameters
iPlayerNode	is the message's zero-based destination.
pMsg	points to the message.
iLength	is the number of bytes in the message.
Description
Call dapiSendWithCRC() to send validated messages to other individual 
Dapi player-nodes. dapiSendWithCRC() computes the sixteen-bit CCITT 
Cyclic Redundancy Check on the message, using the polynomial X16 + X12 
+ X5 + 1. On the destination player-node, dapiRecv() computes the CRC 
upon message arrival and discards the message if there is a CRC mismatch.
In order to provide the fastest possible message delivery, 
dapiSendWithCRC() does not guarantee delivery of the message. Lost 
messages are possible due to modem line noise and/or exceeding 
recommended bandwidth. dapiSendWithCRC() guarantees the delivery order 
of messages.
Do not send messages to dapiThisNode(); attempts to do so result in the error 
DAPI_NoLoopBack.
Call dapiBroadcastWithCRC() to send one message to all other player-nodes. 
It is much better to call dapiBroadcastWithCRC() once than to call 
dapiSendWithCRC() for each other player because dapiBroadcastWithCRC() 
reduces bandwidth consumption.
See Also
	dapiInit()	dapiThisNode()	dapiNodeName()
	dapiSend()	dapiSendAcked()	dapiSendScore()
	dapiBroadcast()	dapiRecv()	dapiClose()
	dapiBroadcastWithCRC()
Example
#include <stdio.h>
#include "dapi.h"

unsigned char Buf [DAPI_MAX_PACKET_SIZE];

void main(int argc, char *argv[])
{
  int iPlayers, iThisPlayerID, i, iErr, iLength;
  unsigned short *pus;

    iPlayers = dapiInit(NULL);

    if (iPlayers <= 0)
    {
        printf("dapiInit() error: %s\n", dapiErrorString(iPlayers)); 
        return;
    }
    printf ("\nNumber of player-nodes: %d\n", iPlayers);

    iThisPlayerID = dapiThisNode();

    //---------------------------------------------------------
    // Make sure dapiThisNode() worked (iThisPlayerID is >= 0)
    // and that there are two or more players in the game.
    //---------------------------------------------------------
    if ((iThisPlayerID < 0) || (iPlayers < 2))
    {
        printf("dapiThisNode() error: %s\n", 
                dapiErrorString(iThisPlayerID));
        return;
    }

    //------------------------------------------------------------
    // Accept a message size as a command line argument. Fill the 
    // message with random numbers to better test the CRC.
    //------------------------------------------------------------
    if (argc >= 2) iLength = atoi (argv[1]);
    else           iLength = 5;

    srand (time(NULL));
    pus = (unsigned short *) &Buf[0];
    for (i = 0; i < min(DAPI_MAX_PACKET_SIZE + 1, iLength); i += 2)
    {
        *pus = rand();
        ++pus;
    }

    for (i = 0; i < iPlayers; ++i)
    {
        //------------------------------------------------
        // Send a message to each of the other players,
        // changing the message slightly for each player.
        //------------------------------------------------
        if (i != iThisPlayerID)
        {
            Buf [0] = i;
            iErr = dapiSendWithCRC (i, Buf, iLength);

            printf("dapiSendWithCRC(to %d, %d bytes): %s\n", 
                   i, iLength, dapiErrorString(iErr));
        }
    }
    
    iErr = dapiBroadcastWithCRC(Buf, iLength);

    printf("dapiBroadcastWithCRC(%d bytes): %s\n", 
            iLength, dapiErrorString(iErr));

    dapiClose();
    return;

} // end-main()--------- dapiSendWithCRC() example ---------------------
int dapiSendAcked(int iDestPlayerNode, unsigned char *pMsg, int iLength);
Return Value
When successful, dapiSendAcked () returns DAPI_NoError. When 
unsuccessful, dapiSendAcked() returns a negative DAPI_ error.
Parameters
iPlayerNode	is the message's zero-based destination.
pMsg	points to the message.
iLength	is the number of bytes in the message.
Description
Call dapiSendAcked() to send validated messages to other individual Dapi 
player-nodes, with delivery guaranteed. dapiSendAcked() computes the 
sixteen-bit CCITT Cyclic Redundancy Check on the message, using the 
polynomial X16 + X12 + X5 + 1. On the destination player-node, dapiRecv() 
computes the CRC upon message arrival and discards the message if there is 
a CRC mismatch.
dapiSendAcked() guarantees delivery of the message and delivery order of 
messages. dapiSendAcked() consumes the most bandwidth, memory and 
processing time of all the dapiSend, so use it sparingly in quick response 
time games and high bandwidth games.
Call dapiRecv() frequently when using dapiSendAcked() because dapiRecv() 
processes arriving acknowledgments and resends unacknowledged messages.
In this Beta release, if one player-node restarts (calls dapiClose() then 
dapiInit()), the other player-node(s) must also restart in order to 
resynchronize the dapiSendAcked() acknowledgment/retry mechanism.
Do not send messages to dapiThisNode(); attempts to do so result in the error 
DAPI_NoLoopBack.
There currently is no Broadcast version of dapiSendAcked(); if there were, it 
would simply call dapiSendAcked() for each of the other player-nodes.
See Also
	dapiInit()	dapiThisNode()	dapiNodeName()
	dapiSend()	dapiSendWithCRC()	dapiSendScore()
	dapiBroadcast()	dapiRecv()	dapiClose()
	dapiBroadcastWithCRC()
Example
#include <stdio.h>
#include "dapi.h"

#define ESCAPE      27
#define BUF_BYTES   3
unsigned char SendBuf [BUF_BYTES] = {0xFF, 0xA5, 0xAA};
unsigned char RecvBuf [DAPI_MAX_PACKET_SIZE];

void main()
{
  int iPlayers, iThisPlayerID, i, iErr, c = 0, iLength, iSource;

    iPlayers = dapiInit(NULL);

    
    if (iPlayers <= 0)
    {
        printf("dapiInit() error: %s\n", dapiErrorString(iPlayers)); 
        return;
    }
    printf ("\nNumber of player-nodes: %d\n", iPlayers);

    iThisPlayerID = dapiThisNode();

    //---------------------------------------------------------
    // Make sure dapiThisNode() worked (iThisPlayerID is >= 0)
    // and that there are two or more players in the game.
    //---------------------------------------------------------
    if ((iThisPlayerID < 0) || (iPlayers < 2))
    {
        printf("dapiThisNode() error: %s\n", 
                dapiErrorString(iThisPlayerID));
        return;
    }

    while (c != ESCAPE)
    {
        if (kbhit() != 0)
        {
            c = getche();
            SendBuf[1] = (unsigned char) c;

            for (i = 0; i < iPlayers; ++i)
            {
                //----------------------------------------------------
                // Send a short message to each of the other players,
                // changing the message slightly for each player.
                //----------------------------------------------------
                if (i != iThisPlayerID)
                {
                    SendBuf [0] = i;
                    iErr = dapiSendAcked(i, SendBuf, BUF_BYTES);

                    printf("\ndapiSendAcked(to %d): %s\n", 
                            i, dapiErrorString(iErr));
                }
            }
        }
        else
        {
            //-----------------------------------------------
            // dapiRecv() handles message acks and resends.
            //-----------------------------------------------
            iLength = DAPI_MAX_PACKET_SIZE;        
            iSource = dapiRecv (RecvBuf, &iLength);
        }
                

    } // end-while().

    dapiClose();
    return;

} // end-main()--------- dapiSendAcked() example -----------------
int dapiSendScore (long lScore);
Return Value
When successful, dapiSendScore() returns DAPI_NoError. When 
unsuccessful, dapiSendScore() returns a negative DAPI_ error.
Parameter
lScore	is this player's current score.
Description
Call dapiSendScore() to tell Dwango the current value of this player's score. 
The Dwango server may display the score in the Dwango lobby or use the 
score for tournaments and leagues.
If the score changes infrequently (like in a football game), call 
dapiSendScore() whenever the score changes. If the score changes rapidly 
(like in a pinball game), call dapiSendScore() periodically (every three to ten 
seconds).
See Also
	dapiInit()	dapiThisNode()	dapiNodeName()
	dapiSend()	dapiSendWithCRC()	dapiSendAcked()
	dapiBroadcast()	dapiRecv()	dapiClose()
	dapiBroadcastWithCRC()
Example
#include <stdio.h>
#include <time.h>
#include "dapi.h"

#define ESCAPE 27

void main( int argc, char *argv[] )
{
  int    iErr, iPlayers, c = 0;
  long   lScore = -3;
  time_t tLastSend = time(NULL), tCurrent, tSendInterval = 3; 

    iPlayers = dapiInit(NULL);

    if (iPlayers <= 0)
    {
        printf("dapiInit() error: %s\n", dapiErrorString(iPlayers)); 
        return;
    }
    printf ("\nNumber of player-nodes: %d\n", iPlayers);

    while (c != ESCAPE)
    {
        if (kbhit() != 0)
        {
            c = getche();
            iErr = dapiSendScore (++lScore);

            printf("  dapiSendScore(%ld): %s\n", 
                   lScore, dapiErrorString(iErr));
            tLastSend = time (NULL);
        }




                
        tCurrent = time(NULL);

        if ((tCurrent - tLastSend) >= tSendInterval)
        {
            iErr = dapiSendScore (++lScore);

            printf("  dapiSendScore(%ld): %s\n", 
                   lScore, dapiErrorString(iErr));
            tLastSend = time (NULL);
        }

    } // end-while().
    return;

} // end-main()--------- dapiSendScore() example ---------------------

int dapiBroadcast (unsigned char *pMsg, int iLength);
Return Value
When successful, dapiBroadcast() returns DAPI_NoError. When 
unsuccessful, dapiBroadcast() returns a negative DAPI_ error.
Parameters
pMsg	points to the message.
iLength	is the number of bytes in the message.
Description
Call dapiBroadcast() to send a single message to all other players. It is much 
better to call dapiBroadcast() once than to call dapiSend() for each other 
player because dapiBroadcast() reduces bandwidth consumption.
In order to provide the fastest possible message delivery, dapiBroadcast() 
does not guarantee delivery of the message or integrity of the message. Lost 
and/or corrupt messages are possible due to modem line noise and exceeding 
recommended bandwidth. 
dapiBroadcast() guarantees the delivery order of messages.
See Also
	dapiInit()	dapiThisNode()	dapiNodeName()
	dapiSend()	dapiSendWithCRC()	dapiSendAcked()
	dapiSendScore()	dapiRecv()	dapiClose()
	dapiBroadcastWithCRC()
Example
#include <stdio.h>
#include "dapi.h"

#define BUF_BYTES   3
unsigned char Buf [BUF_BYTES] = {0xFF, 0xA5, 0xBB};

void main()
{
  int iPlayers, iErr;

    iPlayers = dapiInit(NULL);

    if (iPlayers <= 0)
    {
        printf("dapiInit() error: %s\n", dapiErrorString(iPlayers)); 
        return;
    }
    printf ("\nNumber of player-nodes: %d\n", iPlayers);

    //-------------------------------------------------
    // Broadcast a short message to all other players.
    //-------------------------------------------------
    iErr = dapiBroadcast (Buf, BUF_BYTES);

    printf("dapiBroadcast(): %s\n", dapiErrorString(iErr)); 

    dapiClose();
    return;

} // end-main()--------- dapiBroadcast() example ---------------------
int dapiBroadcastWithCRC (unsigned char *pMsg, int iLength);
Return Value
When successful, dapiBroadcastWithCRC() returns DAPI_NoError. When 
unsuccessful, dapiBroadcastWithCRC() returns a negative DAPI_ error.
Parameters
pMsg	points to the message.
iLength	is the number of bytes in the message.
Description
Call dapiBroadcastWithCRC() to send a single validated message to all other 
players. dapiBroadcastWithCRC() computes the sixteen-bit CCITT Cyclic 
Redundancy Check on the message, using the polynomial X16 + X12 + X5 + 
1. On the destination player-node, dapiRecv() computes the CRC upon 
message arrival and discards the message if there is a CRC mismatch.
 It is much better to call dapiBroadcastWithCRC() once than to call 
dapiSendWithCRC() for each other player because dapiBroadcastWithCRC() 
reduces bandwidth consumption.
In order to provide the fastest possible message delivery, 
dapiBroadcastWithCRC() does not guarantee delivery of the. Lost messages 
are possible due to modem line noise and/or exceeding recommended 
bandwidth. 
dapiBroadcast() guarantees the delivery order of messages.
See Also
	dapiInit()	dapiThisNode()	dapiNodeName()
	dapiSend()	dapiSendWithCRC()	dapiSendAcked()
	dapiSendScore()	dapiBroadcast()	dapiRecv()
	dapiClose()
Example
See example for dapiSendWithCRC().
int dapiRecv (unsigned char *pRecvBuf, int *piLength) 
Return Value
When successful, dapiRecv() returns DAPI_NoError. 
When no messages have arrived, dapiRecv() returns DAPI_NoPacket.
When unsuccessful, dapiRecv() returns a negative DAPI_ error.
Parameters
pRecvBuf	points to the buffer to receive the message. The buffer must 
be at least *piLength bytes in size.
piLength	points to the size of the receive buffer; dapiRecv() changes 
*piLength to be the actual size of the received message.
Description
Call dapiRecv() to receive a message from another player-node. Call 
dapiRecv() frequently to provide fast response time in your game; ignore 
DAPI_NoPacket errors. dapiRecv() receives messages sent using dapiSend(), 
dapiSendWithCRC(), dapiSendAcked(), dapiBroadcast() or 
dapiBroadcastWithCRC().
See Also
	dapiInit()	dapiThisNode()	dapiNodeName()
	dapiSend()	dapiSendWithCRC()	dapiSendAcked()
	dapiSendScore()	dapiBroadcast()	dapiClose()
	dapiBroadcastWithCRC()
Example
#include <stdio.h>
#include "dapi.h"


#define ESCAPE      27
#define BUF_BYTES   400
unsigned char RecvBuf [BUF_BYTES];


void main()
{
  int iPlayers, iSource, c = 0, iLength, iMsgsRcvd = 0, i;

    iPlayers = dapiInit(NULL);

    if (iPlayers <= 0)
    {
        printf("dapiInit() error: %s\n", dapiErrorString(iPlayers)); 
        return;
    }
    printf ("\nNumber of player-nodes: %d\n", iPlayers);

    while (c != ESCAPE)
    {
        if (kbhit() != 0)
        {
            c = getch();
            putch (c);
            printf("\n");
        }
        





        iLength = BUF_BYTES;        
        iSource = dapiRecv (RecvBuf, &iLength);

        if (iSource >= 0)
        {
            printf("%d dapiRecv() from %d, %d bytes (%#x %#x %#x 
....)\n", 
                   ++iMsgsRcvd, iSource, iLength, 
                   RecvBuf[0], RecvBuf[1], RecvBuf[2]);
        }

    } // end-while().

    dapiClose();
    return;

} // end-main()--------- dapiRecv() example ---------------------

int dapiClose();
Return Value
When successful, dapiClose() returns DAPI_NoError. When unsuccessful, 
dapiClose() returns a negative DAPI_ error.
Parameters
None.
Description
Call dapiClose() to close the Dapi connection. Always call dapiClose() when 
your game is exiting.
See Also
	dapiInit()	dapiThisNode()	dapiNodeName()
	dapiSend()	dapiSendWithCRC()	dapiSendAcked()
	dapiSendScore()	dapiBroadcast()	dapiRecv()
	dapiBroadcastWithCRC()
Example
#include <stdio.h>
#include "dapi.h"

void main()
{
  int iPlayers, iErr;

    iPlayers = dapiInit(NULL);

    if (iPlayers <= 0)
    {
        printf("dapiInit() error: %s\n", 
               dapiErrorString(iPlayers)); 
        return;
    }

    printf ("\nNumber of player-nodes: %d\n", iPlayers);

    iErr = dapiClose();

    printf("dapiClose(): %s\n", dapiErrorString(iErr)); 
    return;

} // end-main()-------------- dapiClose() example -------------------



--- End of Dapi Specification ---
Dwango API (Dapi) Specification,  Beta Version 0.2, IVS Confidential.	Page 1 of 20


