![](smile.gif)
about DirectPlay8's DPN_MSGID_RECEIVE message....
do you guys use this message to receive all the datas send by the client computer? well, i was wondering how are you going to manage if you're client sends you mutilple messages with different datas,
ie,
a click sends a mouse coordinate wherien a key pressed sends in a letter pressed, how would you seperate it then using this
PDPNMSG_RECEIVE pMsg = (PDPNMSG_RECEIVE) pMsgBuffer;
pMsg->pReceiveData
[edited by - mickey on April 8, 2002 3:12:34 AM]
![](smile.gif)
http://www.dualforcesolutions.comProfessional website designs and development, customized business systems, etc.,
All messages that arrive from the client will always spawn a DPN_MSGID_RECEIVE message, so you must be able to identify what kind of data that was sent. One way to do this is to have a packet header:
Then you would have a list of different packet types:
Since every packet structure you create begins with a SPacketHeader you can cast the information when it is received on the server, and then check the type code:
Hope you''ll find some of this useful... There are better ways of doing stuff, though (such as placing all received buffers in a list, return DPNSUCCESS_PENDING and then handle all packets in another thread).
// Khaile
// our packet identifierstruct SPacketHeader{ int type;};// the mouse coordinatestruct SPacketCoordinate{ SPacketHeader header; // packet type int x; // mouse coordinate int y;};// a letterstruct SPacketLetter{ SPacketHeader header; // packet type char letter;};
Then you would have a list of different packet types:
enum EPacketTypes{ PT_COORDINATE, PT_LETTER,};
Since every packet structure you create begins with a SPacketHeader you can cast the information when it is received on the server, and then check the type code:
PDPNMSG_RECEIVE pMsg = (PDPNMSG_RECEIVE) pMsgBuffer;SPacketHeader* header = (SPacketHeader*)pMsg->pReceiveData;switch (header->type){ default: // error stuff here break; case PT_COORDINATE: { SPacketCoordinate* coordinate = (SPacketCoordinate*)header; // do stuff with the packet here } break; case PT_LETTER: { SPacketLetter* letter = (SPacketLetter*)header; // do stuff with the packet here } break;}
Hope you''ll find some of this useful... There are better ways of doing stuff, though (such as placing all received buffers in a list, return DPNSUCCESS_PENDING and then handle all packets in another thread).
// Khaile
My Stuff : [ Whispers in Akarra (online rpg) || L33T WAR (multiplayer game) || The Asteroid Menace (another game) ]
yes you have a very very helpful point there but wait...
you see, when you use the SendTo function, you send the contents of a variable, so are you going to like, append a information on the variable so that...
SPacketHeader* header = (SPacketHeader*)pMsg->pReceiveData;switch (header->type)
{ default: // error stuff here break;
case PT_COORDINATE:
{SPacketCoordinate* coordinate = (SPacketCoordinate*)header; // do stuff with the packet here }break;
would work?
so in the variable, you would like put in a PT_COORDINATE?
hope you got what i mean,
also is it possible at the same time to send two variables?
so forexample, i''d send first a boolen variable then after that the ''real'' content so on my
case DPN_MSGID_RECEIVE:
i could check the boolean variable and process the real contents accordingly...
thanks soo much for your comments Khaile, hope to hear from you again,
you see, when you use the SendTo function, you send the contents of a variable, so are you going to like, append a information on the variable so that...
SPacketHeader* header = (SPacketHeader*)pMsg->pReceiveData;switch (header->type)
{ default: // error stuff here break;
case PT_COORDINATE:
{SPacketCoordinate* coordinate = (SPacketCoordinate*)header; // do stuff with the packet here }break;
would work?
so in the variable, you would like put in a PT_COORDINATE?
hope you got what i mean,
also is it possible at the same time to send two variables?
so forexample, i''d send first a boolen variable then after that the ''real'' content so on my
case DPN_MSGID_RECEIVE:
i could check the boolean variable and process the real contents accordingly...
thanks soo much for your comments Khaile, hope to hear from you again,
![](smile.gif)
http://www.dualforcesolutions.comProfessional website designs and development, customized business systems, etc.,
okey i think this is much simpler,
how can my
pMsg->pReceiveData;
contain a mouse coordinate and a letter at the same time?
how can my
pMsg->pReceiveData;
contain a mouse coordinate and a letter at the same time?
![](smile.gif)
http://www.dualforcesolutions.comProfessional website designs and development, customized business systems, etc.,
ok.... ![](smile.gif)
If you want to do it the really easy way you just create a single structure that holds all the information you need:
Then on the server you just cast the message buffer to a packet pointer and read its contents:
// Khaile
![](smile.gif)
If you want to do it the really easy way you just create a single structure that holds all the information you need:
struct SPacket{ // mouse coordinate: int x; int y; // letter: char letter;};// when you send (from the client) you do something like this...SPacket packet;... // set packet informationDPN_BUFFER_DESC bufferdesc;bufferdesc.dwBufferSize = sizeof(SPacket); // set the size of the packet you''re sendingbufferdesc.pBufferData = (unsigned char*)&packet... // send packet
Then on the server you just cast the message buffer to a packet pointer and read its contents:
SPacket* packet = (SPacket*)pMsg->pReceiveData;// do stuff with the packet...doStuffWithCoordinates(packet->x, packet->y);// etc etc etc :)
// Khaile
My Stuff : [ Whispers in Akarra (online rpg) || L33T WAR (multiplayer game) || The Asteroid Menace (another game) ]
![](smile.gif)
![](smile.gif)
![](smile.gif)
ahhhhh..... so it's like that
![](smile.gif)
![](smile.gif)
wow thanks a lot khailie!!
[edited by - mickey on April 8, 2002 11:34:32 AM]
http://www.dualforcesolutions.comProfessional website designs and development, customized business systems, etc.,
follow up question pls...
why do we need to use the
IDirectPlay8Peer::EnumHost() function after successfully using the AddComponent()? i''m confuse, because we already put in the IP address of the host right? so why need this?
SDK definition:
Enumerates applications that host Microsoft® DirectPlay® games. When an application is found that meets the enumeration criteria, the application''s message handler is called with a DPN_MSGID_ENUM_HOSTS_RESPONSE system message. The message contains a DPN_APPLICATION_DESC structure describing the applications found and IDirectPlay8Address objects identifying the location of the hosts.
---------
some things that confuse me is...
identifying the location of the hosts? aren''t i just did that using AddComponent?
thanks,
why do we need to use the
IDirectPlay8Peer::EnumHost() function after successfully using the AddComponent()? i''m confuse, because we already put in the IP address of the host right? so why need this?
SDK definition:
Enumerates applications that host Microsoft® DirectPlay® games. When an application is found that meets the enumeration criteria, the application''s message handler is called with a DPN_MSGID_ENUM_HOSTS_RESPONSE system message. The message contains a DPN_APPLICATION_DESC structure describing the applications found and IDirectPlay8Address objects identifying the location of the hosts.
---------
some things that confuse me is...
identifying the location of the hosts? aren''t i just did that using AddComponent?
thanks,
![](smile.gif)
http://www.dualforcesolutions.comProfessional website designs and development, customized business systems, etc.,
Hmm... I''m not completely sure, but I think AddComponent only sets some settings for the connection while EnumHosts searches for active games. Your game will work even if you don''t use EnumHosts to find games, you just need to know the connection address.
// Khaile
// Khaile
My Stuff : [ Whispers in Akarra (online rpg) || L33T WAR (multiplayer game) || The Asteroid Menace (another game) ]
Btw, this is a multiplayer game i''ve made with DirectPlay... Hope it will spawn some inspiration ![](wink.gif)
http://www.gamedev.net/community/gds/projects/default.asp?projectID=502
![](wink.gif)
http://www.gamedev.net/community/gds/projects/default.asp?projectID=502
My Stuff : [ Whispers in Akarra (online rpg) || L33T WAR (multiplayer game) || The Asteroid Menace (another game) ]
hi khalie, yeah i''ve seen the games you guys made, your from oblivion-games right and it seems you''re already a prof. game developer, cool!
okey hope you don''t mind me telling you about this, you see, i tried removing the EnumHost many times and all those times my program didn''t connect, this is my way to connect to a host, stripped from the SDK,
CoCreateInstance( CLSID_DirectPlay8Address, NULL,
CLSCTX_INPROC_SERVER,
IID_IDirectPlay8Address,
(LPVOID*) &lpdpHostAddress);
lpdpHostAddress->SetSP( &CLSID_DP8SP_TCPIP );
WCHAR wszHost[128] = L" . . . "; // the host ip address...
pdpHostAddress->AddComponent(DPNA_KEY_HOSTNAME, wszHost,
2*(wcslen(wszost) + 1), DPNA_DATATYPE_STRING );
lpdpPeer->EnumHosts( &dpAppDesc, lpdpHostAddress,
lpdpDeviceAddress,
NULL, 0, 4, 0, 0, NULL, NULL, DPNENUMHOSTS_SYNC );
dp.lpdpPeer->Connect(&dpAppDesc,
lpdpHostAddress, lpdpDeviceAddress,
NULL,
NULL,
NULL, 0,
NULL,
NULL,
NULL,
DPNCONNECT_SYNC);
there
now when i remove the enum host there, it won''t connect,
![](smile.gif)
okey hope you don''t mind me telling you about this, you see, i tried removing the EnumHost many times and all those times my program didn''t connect, this is my way to connect to a host, stripped from the SDK,
CoCreateInstance( CLSID_DirectPlay8Address, NULL,
CLSCTX_INPROC_SERVER,
IID_IDirectPlay8Address,
(LPVOID*) &lpdpHostAddress);
lpdpHostAddress->SetSP( &CLSID_DP8SP_TCPIP );
WCHAR wszHost[128] = L" . . . "; // the host ip address...
pdpHostAddress->AddComponent(DPNA_KEY_HOSTNAME, wszHost,
2*(wcslen(wszost) + 1), DPNA_DATATYPE_STRING );
lpdpPeer->EnumHosts( &dpAppDesc, lpdpHostAddress,
lpdpDeviceAddress,
NULL, 0, 4, 0, 0, NULL, NULL, DPNENUMHOSTS_SYNC );
dp.lpdpPeer->Connect(&dpAppDesc,
lpdpHostAddress, lpdpDeviceAddress,
NULL,
NULL,
NULL, 0,
NULL,
NULL,
NULL,
DPNCONNECT_SYNC);
there
![](smile.gif)
![](smile.gif)
http://www.dualforcesolutions.comProfessional website designs and development, customized business systems, etc.,
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement