I have been trying to learn DirectPlay with the assistance of MSDN and the source code bundled with the directX 8.1 SDK.
Problem: Connection works fine, server successfully retrieves client data, but in the following attempt to send a welcome message from the server, the output on the client's side is "Server Sent: " instead of "Server Sent: Welcome to the Server!" I've been going over my code over and over again.. I am pretty sure directplay is not the problem, more likely I've lost something essential in the conversion of and output of data.
Related code in header file included in both server and client program:
#define MAX_CHAT_LENGTH 40
#define GAME_MSGID_BROADCAST 6
struct GAMEMSG_GENERIC
{
DWORD dwType;
};
struct GAMEMSG_BROADCAST : public GAMEMSG_GENERIC
{
CHAR strBroadcast[MAX_CHAT_LENGTH]; // message to be sent
};
Code in server program:
GAMEMSG_BROADCAST msgBroadcast;
msgBroadcast.dwType = GAME_MSGID_BROADCAST;
strcpy (msgBroadcast.strBroadcast,"Welcome to the Server!");
DPN_BUFFER_DESC bufferDesc;
bufferDesc.dwBufferSize = sizeof(GAMEMSG_BROADCAST);
bufferDesc.pBufferData = (BYTE*) &msgBroadcast;
g_pDPServer->SendTo( dpnidNewPlayer, &bufferDesc, 1,
0, NULL, NULL, DPNSEND_SYNC );
Code in client program:
case DPN_MSGID_RECEIVE:
{
PDPNMSG_RECEIVE pReceiveMsg;
pReceiveMsg = (PDPNMSG_RECEIVE)pMsgBuffer;
GAMEMSG_GENERIC* pMsg = (GAMEMSG_GENERIC*) pReceiveMsg->pReceiveData;
switch( pMsg->dwType )
{
case GAME_MSGID_BROADCAST:
{
// We're getting a text message from the server
GAMEMSG_BROADCAST* pBroadcastMsg;
pBroadcastMsg = (GAMEMSG_BROADCAST*)pReceiveMsg->pReceiveData;
printf("\nServer Sent: %S\n", (CHAR *) pBroadcastMsg->strBroadcast);
break;
};
}
break;
}
Now, I know that the data is sent. By adding in some debug code, I find that the above case IS triggered. However, all that is outputted is "Server Sent: " Other types of communication between the two programs have been successful, but I cannot get this one to work. What am I missing? What's wrong? I appreciate the help in advance!