Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3605358
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:06:47+00:00 2026-05-18T21:06:47+00:00

I’m making a webserver and I’ve come up with some very strange problems. My

  • 0

I’m making a webserver and I’ve come up with some very strange problems.

  1. My server was running as expected
    yesterday when I turned off my laptop, but today it only sends the http
    headers (I didn’t change anything)
  2. When a user requests a file, if I send them using the following code, it works perfectly:

while ((n = fread(data, 1, sizeof(data), file)) > 0)
send(ts, data, n, 0);

but if I change it to this, it only sends ~2% of the file. And that’s not a random number, it actually only sends about 2% of the file.

while ((n = fread(data, 1, sizeof(data), file)) > 0)
web.Send(data);

int WEB::Send(string data)
{
    return send(TempSocket, data.c_str(), data.size(), 0);
}

changing string to char* doesn’t solve the problem.

  • I’m using visual studio2010. If I run
    my code step-by-step, I am able to
    solve problem #1, everything gets sent. And that is my main
    problem. I do not understand why it
    happens. Hopefully someone can
    explain it to me.

Thanks in advance.

EDIT:

int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrev, LPSTR lpCmd,int nShow)
{
    SOCKET MainSocket=0;
    MSG msg;


    RedirectIOToConsole();





    CreateThread(NULL, NULL, ListenThread, NULL, NULL, NULL);



    while (GetMessage(&msg, NULL, 0, 0)) 
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }


    WSACleanup();
    closesocket(MainSocket);
    MainSocket = INVALID_SOCKET;

    return msg.wParam;
}

DWORD WINAPI ListenThread(LPVOID lparam)
{
    SOCKET MainSocket;
    WSADATA wsaData;
    SOCKET tmpsock;
    struct sockaddr_in local, from;
    int fromlen=sizeof(from);

    WSAStartup(MAKEWORD(2, 2), &wsaData);


    local.sin_family=AF_INET;
    local.sin_addr.s_addr=INADDR_ANY;
    local.sin_port=htons(PORT);
    MainSocket=socket(AF_INET,SOCK_STREAM,0);

    if(MainSocket==INVALID_SOCKET)
    {
        return 0;
    }
    if(bind(MainSocket,(struct sockaddr*)&local,sizeof(local))!=0)
    {
        return 0;
    }
    if(listen(MainSocket,10)!=0)
    {
        return 0;
    }


    while(1)
    {
        tmpsock = accept(MainSocket,(struct sockaddr*)&from,&fromlen);
        CreateThread(NULL, NULL, SlaveThread, (LPVOID)tmpsock, NULL, NULL);
    }

}

DWORD WINAPI SlaveThread(LPVOID lparam)
{
    SOCKET ts = (SOCKET)lparam;//temporary socket
......

char data[4096];
                    int n;
                    unsigned long int length = statbuf.st_size;

                    web.SendHeaders(200, "OK", format("Content-Disposition: attachment; filename=\"%s\"", FileName.c_str()).c_str(), web.GetMimeType(ReqPath.c_str()), length, statbuf.st_mtime);
                    unsigned long int i=0,d=0;
                    while ((n = fread(data, 1, sizeof(data), file)) > 0)
                    {
                        d+=send(ts, data, n, 0);
                        i+=n;
                    }
                    printf("%i=%i=%i\n", length,i,d);
                    fclose(file);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T21:06:48+00:00Added an answer on May 18, 2026 at 9:06 pm

    Assuming that data is char[] of some size, and that string is std::string your code doesn’t do what you think it does. When you pass data to WEB::Send it’s creating a std::string from all the bytes in data up to the first 0, which probably is about 2% of the total data. You want to call web.Send(std::string(data, n)); instead.

    Also in WEB::Send you need to call data.data() instead of c_str() to avoid the same problems with nulls.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a French site that I want to parse, but am running into
I'm making a simple page using Google Maps API 3. My first. One marker
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.