Hello Ive been reading some networking tutorials online some most don't seem to be consistent on sending bit of winsock can't explain by word alone so ill give an example to make thnigs clear...
struct UnitInfo
{
stPacketHeader stHeader;
int iUnitID;
int iUnitType;
int iUnitHealth;
int iUnitFireRate;
int UnitXPos;
int UnitYPos;
}
struct UserInfo
{
stPacketHeader stHeader;
int UserID;
char szUserName[50];
char szUserIP[16];
}
struct UnitInfo g_stiSPacketUnitInfo;
struct UserInfo g_stiSPacketUserInfo;
char szSendPacketBuffer[2000];
int iSizeOfSentData = 0;
some where in code after i fill in the structs with info then memcpy the struct in to the szSendPacketBuffer......
Is it better to send it with the size of the struct prototype,
iSizeOfSentData = ClientSocObject.iSend(szSendBuffer,sizeof(UserInfo),0);
or send it with the sizeof the struct instance
iSizeOfSentData = ClientSocObject.iSend(szSendBuffer,sizeof(g_stiSPacketUserInitInfo),0);
or the size of the buffer
iSizeOfSentData = ClientSocObject.iSend(szSendBuffer,sizeof(szSendBuffer),0);
no suprise i get diffrent results for iSizeOfSentData but i was wondering which is better programming practice and safer?
I think logically its better to send with size of the struct instance but i am a bit worried that be might bad and cause some data/memory error or problems?