Original Post
Hey Guys, Im converting a project that I had made from using a union for the transfer of packets over sockets to dynamic sizes of frames. Now I've got the receiving code sorted out, but before with the union I would stack a bunch of frames ontop of eachother before sending. Now I want to convert that stacking that I was doing into using different sized frames. Would the following be how I would do what I use to do? TCHAR* spSend = new TCHAR[(sizeof(SPName)*3) + sizeof(SPMessage)]; If that is then awesome, Imma keep on trecking cause theres alot of changes but pleas eif it doesn't seem right let me know before I change the entire program over to test it, only to find out that that is wrong. I'll be reinpretcasting the data on the receiving end, so Im just trying to make a buffer that has enough bytes to hold the two different structs. In the above example I'm trying to create room for 3 SPName packets of one size, and one SPMessage packet of another size. Again thanks for any help that anyone provides me. Ohya and then after I create spSend, how would I assign the packets properly to the buffer? Im still trying to get my head around this stuff, and Im already 197 errors and 3 warnings deep into programming :p So I gotta go ahead with my changes. Here is what Im attempting to do so far... [Edited by - Surg AKA Kunark on December 16, 2005 3:50:13 PM]
if(iPlayers > 1)
{
// Number of players minus yourself
TCHAR* spSend = new TCHAR[(sizeof(SPName)*(iPlayers-1)) + sizeof(SPMessage)];
///////////////////////////////////////////////
///////////////////////////////////////////////
for(int i(0), iPos(0); i < 4; i++){
if(m_pDlg->m_bPlayers){
/*
Populates array with player names currently playing.
Pointless to send your own name so that name is not
ever sent.
*/
if(i != m_iPlayer){
reinterpret_cast<SPName*>(spSend)[iPos].iServerFlag = SERVERDATA_NAME;
reinterpret_cast<SPName*>(spSend)[iPos].iPlayer = i;
strcpy(reinterpret_cast<SPName*>(spSend)[iPos].szName, m_pDlg->m_cbsBuggies->szName);
iPos++;
}
}
}
//////////////////////////////////////////////
//////////////////////////////////////////////
/*
The packet array should now be populated.
Now let's append the Authorization Complete
notice to the array.
*/
(*(reinterpret_cast<SPMessage*>(&(reinterpret_cast<SPName*>(spSend)[iPlayers-1])))).iServerFlag = SERVERDATA_MESSAGE;
(*(reinterpret_cast<SPMessage*>(&(reinterpret_cast<SPName*>(spSend)[iPlayers-1])))).iFlag = 5;
(*(reinterpret_cast<SPMessage*>(&(reinterpret_cast<SPName*>(spSend)[iPlayers-1])))).iHighParam = 0;
(*(reinterpret_cast<SPMessage*>(&(reinterpret_cast<SPName*>(spSend)[iPlayers-1])))).iLowParam = 0;
/*
We now are ready to send the packet to the client.
This packet is made up of all the names of the
current players, and the server authorization.
*/
Send(spSend, (sizeof(SPName)*(iPlayers-1)) + sizeof(SPMessage));
delete spSend;
} else {