Re: Sending Struct over UDP
Break into the debugger, and see where you are in the stack. There is not enough code provided to say. Also, please use code tags when posting code.
Viggy
Re: Sending Struct over UDP
Well just looking at your send command, you are sending a reference to a pointer. Should be:
Code:
dwBytes = SendTo((const char *)pStoSend, sizeof(*pStoSend), m_nPort,m_strRemote);
Quote:
dwBytes = SendTo((const char *)&pStoSend, sizeof(*pStoSend), m_nPort,m_strRemote);
//Receive
nRead = ReceiveFrom((char *)&pStoReceive, 699999, m_strRemote, m_nPort);
Anyone here that can help me with this problem?
Re: Sending Struct over UDP
Do I need to convert the struct into bytes before sending it or is this the correct way of sending a struct over UDP?
Re: Sending Struct over UDP
Its fine.
Is your server echoing the bytes back?
nRead = ReceiveFrom((char *)&pStoReceive, sizeof(StoSend), m_strRemote, m_nPort);
Re: Sending Struct over UDP
dwBytes = SendTo((const char *)&pStoSend, sizeof(*pStoSend), m_nPort,m_strRemote);
nRead = ReceiveFrom((char *)&pStoReceive, sizeof(StoSend), m_strRemote, m_nPort);
Sending a struct of 24 bytes local the pStoReceive is received correctly, however sending more then 24 bytes I get a error msg: Unhandled exception at 0x7c1772af (mfc71d.dll) in Device.exe: 0xC0000005: Access violation reading location 0x00000f94.
using: LAN PC to PC no data is transmitted correctly?
using: dwBytes = SendTo((const char *)pStoSend, sizeof(*pStoSend), m_nPort,m_strRemote); no data is transmitted correctly?
Re: Sending Struct over UDP
If you are going to send an array you are going to have to multiply and reflect that in your sendto and recvfrom.
sizeof(StoSend) * nArrayElements
Re: Sending Struct over UDP
Finally found the correct way, the problem is unneeded casting and incorrect handling of pointers :)
dwBytes = SendTo(pStoSend, sizeof(*pStoSend), m_nPort,m_strRemote);
nRead = ReceiveFrom(pStoReceive, sizeof(*pStoReceive), m_strRemote, m_nPort);
Re: Sending Struct over UDP
Well you really shouldn't use sizeof on a dereferenced pointer, you should use sizeof on a type.
Hence:
Code:
dwBytes = SendTo(pStoSend, sizeof(StoSend), m_nPort,m_strRemote);
nRead = ReceiveFrom(pStoReceive, sizeof(StoReceive), m_strRemote, m_nPort);