Hullo. I made a small webserver just to flex my winsock muscle, but it only works for small files like html files.

Once I have processed the request to get the path of the file, I send the result like this:

ifstream fin;, ios_base::binary | ios_base::in);
if (!fin.good() || fin.eof() || !fin.is_open())
{"404.html", ios_base::binary | ios_base::in);

fin.seekg(0, ios::end);
unsigned int lenFile = (unsigned int)fin.tellg();
char *webpage = new char[lenFile];
fin.seekg(0, ios::beg);, lenFile);

wsabuffer.buf = webpage;
wsabuffer.len = lenFile;

WSASend(socket, &wsabuffer, 1, NULL, flags, &wsaOverlapped, SendComplete);


Like I said, it works with small files like the html files, but when I try to send a larger file like "" it just freezes.

I previously made a direct-connection 2way file transfer program, in which I created a worker thread that looped, sending 8192 byte chunks until the socket blocked, and then pause to wait for an FD_WRITE event before the loop continued. This didn't work for the web server though:confused:

For the web server, I have overlapped sockets set up, whereas the 2way app was only using the regular send(). So in the web server, I tried this:

int bytesSent = 0;
int chunk;
while(bytesSent <= lenFile)
	if(lenFile - bytesSent >= CHUNKSIZE)
		chunk = CHUNKSIZE;
		chunk = lenFile - bytesSent;

	wsabuffer.buf = buffer;
	wsabuffer.len = chunk;, chunk);
	WSASend(socket, &wsabuffer, 1, NULL, flags, &wsaOverlapped, SendComplete);
	SleepEx(INFINITE, TRUE); //wait for send to complete before next chunk is attempted
	bytesSent += chunk;

but it hung too:'(
I let it sit for a while once, and when I finally hit stop on the browser like 2 mins later, I had about 20 seconds of the song sitting there.

can anyone help me out? part of the problem is that I don't know how a browser would expect to receive something like this

lol..its ok. The problem was that I wasn't sending a proper http response header before sending the data.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.