winsock , can't receive the file data .


hi there ,

i'm new c++ winsock programmer , i'm writing c++ code using Winsock so i can send a text file from client to server , the problem is the server is not receiving the full content of the txt file if it was too long , i.e: if the file contain "hello" this may work ,but if the file contain "hello how are you? fine ? " -> this don't arrive to the server and no file is even created !

please help me receiving the full file , here is the code :

Server Receive Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

  int Size;
    char *Filesize = new char[1024];

    if(recv(ClientSocket, Filesize, 1024, 0)) // File size
    {
        Size = atoi((const char*)Filesize);
        printf("File size: %d\n", Size);
    }

    char *Buffer = new char[Size];

    if(recv(ClientSocket, Buffer, Size, 0)) // File Binary
    {
        FILE *File;
        File = fopen("E:\\file2.txt", "wb");
        fwrite((const char*)Buffer, 1, Size, File);
        fclose(File);
    }

	std::cout<<"File Receive done ";


Client Send Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
 

	//Send A File ///
	FILE *File;
        char *Buffer;
        unsigned long Size;

        File = fopen("E:\\file1.txt", "rb");

    //File = fopen("file1.txt", "rb");
        if(!File)
        {
            printf("Error while readaing the file\n");
           
        }

    fseek(File, 0, SEEK_END);
        Size = ftell(File);
        fseek(File, 0, SEEK_SET);

    Buffer = new char[Size];

        fread(Buffer, Size, 1, File);
        char cSize[MAX_PATH];
        sprintf(cSize, "%i", Size);
		printf("file size is %s ",cSize);
        fclose(File);

        send(ConnectSocket, cSize, MAX_PATH, 0); // File size
        send(ConnectSocket, Buffer, Size, 0); // File Binary
        free(Buffer);

guys you answered a lot of questions like this one please mine is different so please help me fix this issue .
I would first check the return values of your socket calls. Are you getting any error codes?
no i don't get any error code , let me post you an image of the client data before send and the server data received .

http://s14.postimg.org/6jt0r72sh/run2.jpg
Last edited on
For this problem you can use Long Path Toll and you will solve.
aphelix , please can you tell me more about it ? what this tool have to do with my problem ?!





Last edited on
Topic archived. No new replies allowed.