Pleas help me correct a strange bug.
-
I'm programming winsock. In my app i'm building in a feature for sending multiple files over the internet. In the filesend request i set up a loop where i send the filename and -size of the files the user has chosen to send. My problems is this: the second time the sender of the files calls the recv function to receive the "GETSIZE" string, then, instead of receiving "GETSIZE" it receives the "GETSIZE" string but shifted one place to the right, so it's actually "\0GETSIZE" without a terminating null but with a starting null instead. Here are the loops how they look on the sender's and the receiver's side. Receiver's side:
char szTempChar[512];
DWORD dwTotalFileSize = 0;
char szFileName[MAX_PATH+1];
bool bStop = false;
char szRecvBuff[513];
i = send(sckClient, "GETFILENAME", 12, 0);
i = recv(sckClient, szRecvBuff, 512, 0);
while (bStop == false)
{
strcpy(szFileName, szRecvBuff); i = send(sckClient, "GETSIZE", 8, 0); i = recv(sckClient, szRecvBuff, 512, 0); dwTotalFileSize = dwTotalFileSize + atoi(szRecvBuff); sprintf(szTempChar, "%s, %s bytes\\r\\n", szFileName, szRecvBuff); AddText(ghMultipleWnd, IDC\_MULTIPLEFILENAMEREQUEST, szTempChar); i = send(sckClient, "GETFILENAME", 12, 0); i = recv(sckClient, szRecvBuff, 512, 0); if (!strcmp(szRecvBuff, "\\\\DONE")) bStop = true;}
}
and the sender's side (szCompleteFileName is an array of char * pointing to a string that is the path to one of the files the user wants to send. GetFileName is a function that strips the path away from the complete filename
HANDLE hCheckFile
char szTempChar[512];
DWORD dwCurrentFileSize = 0;
char szFileName[MAX_PATH+1];
bool bStop = false;
char szRecvBuff[513];
int iFileCount = 0;
DWORD dwCurrentFileSize = 0;
i = recv(sckClient, szRecvBuff, 12, 0);
while (iFileCount+1 <= SendMessage(GetDlgItem(ghWnd, IDC_FILES), LB_GETCOUNT, 0, 0))
{
if (!strcmp("GETFILENAME", szRecvBuff)) { strcpy(szRecvBuff, szCompleteFileName\[iFileCount++\]); GetFileName(szRecvBuff); send(sckClient, szRecvBuff, strlen(szRecvBuff)+1, 0); i = recv(sckClient, szRecvBuff, 8, 0); if (!strcmp("GETSIZE", szRecvBuff)) { if ((hCheckFile = CreateFile(szCompleteFileName\[iFileCount\], GENERIC\_READ, FILE\_SHARE\_READ, NULL, OPEN\_EXISTING, FILE\_ATTRIBUTE
-
I'm programming winsock. In my app i'm building in a feature for sending multiple files over the internet. In the filesend request i set up a loop where i send the filename and -size of the files the user has chosen to send. My problems is this: the second time the sender of the files calls the recv function to receive the "GETSIZE" string, then, instead of receiving "GETSIZE" it receives the "GETSIZE" string but shifted one place to the right, so it's actually "\0GETSIZE" without a terminating null but with a starting null instead. Here are the loops how they look on the sender's and the receiver's side. Receiver's side:
char szTempChar[512];
DWORD dwTotalFileSize = 0;
char szFileName[MAX_PATH+1];
bool bStop = false;
char szRecvBuff[513];
i = send(sckClient, "GETFILENAME", 12, 0);
i = recv(sckClient, szRecvBuff, 512, 0);
while (bStop == false)
{
strcpy(szFileName, szRecvBuff); i = send(sckClient, "GETSIZE", 8, 0); i = recv(sckClient, szRecvBuff, 512, 0); dwTotalFileSize = dwTotalFileSize + atoi(szRecvBuff); sprintf(szTempChar, "%s, %s bytes\\r\\n", szFileName, szRecvBuff); AddText(ghMultipleWnd, IDC\_MULTIPLEFILENAMEREQUEST, szTempChar); i = send(sckClient, "GETFILENAME", 12, 0); i = recv(sckClient, szRecvBuff, 512, 0); if (!strcmp(szRecvBuff, "\\\\DONE")) bStop = true;}
}
and the sender's side (szCompleteFileName is an array of char * pointing to a string that is the path to one of the files the user wants to send. GetFileName is a function that strips the path away from the complete filename
HANDLE hCheckFile
char szTempChar[512];
DWORD dwCurrentFileSize = 0;
char szFileName[MAX_PATH+1];
bool bStop = false;
char szRecvBuff[513];
int iFileCount = 0;
DWORD dwCurrentFileSize = 0;
i = recv(sckClient, szRecvBuff, 12, 0);
while (iFileCount+1 <= SendMessage(GetDlgItem(ghWnd, IDC_FILES), LB_GETCOUNT, 0, 0))
{
if (!strcmp("GETFILENAME", szRecvBuff)) { strcpy(szRecvBuff, szCompleteFileName\[iFileCount++\]); GetFileName(szRecvBuff); send(sckClient, szRecvBuff, strlen(szRecvBuff)+1, 0); i = recv(sckClient, szRecvBuff, 8, 0); if (!strcmp("GETSIZE", szRecvBuff)) { if ((hCheckFile = CreateFile(szCompleteFileName\[iFileCount\], GENERIC\_READ, FILE\_SHARE\_READ, NULL, OPEN\_EXISTING, FILE\_ATTRIBUTE
-
I'm programming winsock. In my app i'm building in a feature for sending multiple files over the internet. In the filesend request i set up a loop where i send the filename and -size of the files the user has chosen to send. My problems is this: the second time the sender of the files calls the recv function to receive the "GETSIZE" string, then, instead of receiving "GETSIZE" it receives the "GETSIZE" string but shifted one place to the right, so it's actually "\0GETSIZE" without a terminating null but with a starting null instead. Here are the loops how they look on the sender's and the receiver's side. Receiver's side:
char szTempChar[512];
DWORD dwTotalFileSize = 0;
char szFileName[MAX_PATH+1];
bool bStop = false;
char szRecvBuff[513];
i = send(sckClient, "GETFILENAME", 12, 0);
i = recv(sckClient, szRecvBuff, 512, 0);
while (bStop == false)
{
strcpy(szFileName, szRecvBuff); i = send(sckClient, "GETSIZE", 8, 0); i = recv(sckClient, szRecvBuff, 512, 0); dwTotalFileSize = dwTotalFileSize + atoi(szRecvBuff); sprintf(szTempChar, "%s, %s bytes\\r\\n", szFileName, szRecvBuff); AddText(ghMultipleWnd, IDC\_MULTIPLEFILENAMEREQUEST, szTempChar); i = send(sckClient, "GETFILENAME", 12, 0); i = recv(sckClient, szRecvBuff, 512, 0); if (!strcmp(szRecvBuff, "\\\\DONE")) bStop = true;}
}
and the sender's side (szCompleteFileName is an array of char * pointing to a string that is the path to one of the files the user wants to send. GetFileName is a function that strips the path away from the complete filename
HANDLE hCheckFile
char szTempChar[512];
DWORD dwCurrentFileSize = 0;
char szFileName[MAX_PATH+1];
bool bStop = false;
char szRecvBuff[513];
int iFileCount = 0;
DWORD dwCurrentFileSize = 0;
i = recv(sckClient, szRecvBuff, 12, 0);
while (iFileCount+1 <= SendMessage(GetDlgItem(ghWnd, IDC_FILES), LB_GETCOUNT, 0, 0))
{
if (!strcmp("GETFILENAME", szRecvBuff)) { strcpy(szRecvBuff, szCompleteFileName\[iFileCount++\]); GetFileName(szRecvBuff); send(sckClient, szRecvBuff, strlen(szRecvBuff)+1, 0); i = recv(sckClient, szRecvBuff, 8, 0); if (!strcmp("GETSIZE", szRecvBuff)) { if ((hCheckFile = CreateFile(szCompleteFileName\[iFileCount\], GENERIC\_READ, FILE\_SHARE\_READ, NULL, OPEN\_EXISTING, FILE\_ATTRIBUTE