Client sending code
void CClient::Upload(char *szFile)
{
FILE *pFile = fopen(szFile, "rb");
char szBuffer[1000];
int iReaded = fread(szBuffer, sizeof(char), 1000, pFile);
szBuffer[iReaded] = '\0';
while(iReaded > 0)
{
// Prepare the packet
stPacket packet;
packet.packetType = PACKET_TYPE_DOWNLOADING;
packet.iClientID = m_iClientID;
strcpy(packet.szBuffer, szBuffer);
// Send the packet
GetSocket()->Send((const char *)&packet, sizeof(packet), NULL, -1);
printf("Readed: %d\n", iReaded);
// Read the next buffer
iReaded = fread(szBuffer, sizeof(char), 1000, pFile);
szBuffer[iReaded] = '\0';
printf("new read %d\n", iReaded);
}
// Prepare the finish packet
stPacket packet;
packet.packetType = PACKET_TYPE_DOWNLOAD_FINISH;
packet.iClientID = m_iClientID;
// Send the packet
GetSocket()->Send((const char *)&packet, sizeof(packet), NULL, -1);
}
My packet structure
struct stPacket
{
int iClientID; // Client id who sended the packet
ePacketType packetType; // Type of packet that
// **** files informations **** //
int iFilesCount; // Number of files sended
char szFile[100][512]; // Files names
// **** functions variables(Reserved) **** //
char szBuffer[1000]; // buffer used for functions calling or file transferring
};
Server receiving code
void CServer::StartDownload(char *szFile)
{
m_pFile = fopen(szFile, "wb");
if(!m_pFile)
return;
m_bDownloading = true;
}
void CServer::Download(char *szBuffer)
{
if(!m_bDownloading)
return;
fputs(szBuffer, m_pFile);
}
void CServer::EndDownload()
{
fclose(m_pFile);
m_bDownloading = false;
}
the CServer::Download is called every time the downloading packet is received and the szBuffer is the buffer sended
My socket is SOCK_DGRAM(no connect neither accept functions are called) and its using UDP port(i know its recommended to use TCP but i want to use SOCK_DGRAM wich dosent support TCP port connections)
the probleme is that when i start sending the file i got that
Readed 1000 Next Read 1000 Readed 1000 Next Read 1000 ... Readed 756 Next Read 0
then the client window crashs saying "Run time check Failure #3: the Stack around 'szBuffer' was corrupted"
i dont see anything wrong with my code
also when the download is finished, it dosent send the whole file, i mean im trying to send a picture with the size of 111 Kb and i got only a picture with a ~3 kb, whats the probleme with my code ?
thanks in advance

New Topic/Question
Reply



MultiQuote






|