I can create and bind the socket between client/server.
But this is sorta what I have for the client:
HANDLE fFile;
char *sp;
int iFileLength;
...
hFile = CreateFile (szFileName,
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
0,
NULL);
if(hFile == INVALID_HANDLE_VALUE)
{
MessageBox(hwnd, "Cannot open file", "File", MB_OK);
}
iFileLength = GetFileSize(hFile, NULL) ;
sp = (char*)malloc(sizeof(iFileLength+2));
while(ReadFile(hFile, sp, BUFSIZE, &dwBytesRead, NULL) && iFileLength > 0)
{
send(sd, sp, BUFSIZE, 0);
iFileLength -= dwBytesRead;
sp += dwBytesRead;
}
CloseHandle(hFile);
free(sp);
Within the server, I have a while loop that reads from recv()
#define BUFSIZE 512
char *bp, buf[BUFSIZE];
...
bp = buf;
while((n = recv(send_sd, bp, BUFSIZE, )) <= BUFSIZE)
{
if(n == 0)
break;
printf("%s\n", bp);
bp += n;
bytes_to_read -= n;
}
Now what I am seeing is
1. the server stops after 512 byte are read (i would assume it has something to do with the while loop going to BUFSIZE)
2. the client tends to die a horrific death as I think I am corrupting the heap.
I"m trying to learn... i've spent all day trying to get my client (GUI) to send a file to server (console) and just display it to stdout.
lol


Sign In
Create Account


Back to top










