data gets corrupted (c sockets)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


Hi,

I've been working on a project and I have a task which consists on
coding the transference
of a stream of bytes on the network using controlled bandwidth and being able to
download this data on a regular web browser.

The fact is that whenever I try to download any file through the web
browser (Mozilla Firefox 3.6.3),
some bytes from the end of the file always gets corrupted.

I've tried to download several files using wget and it works fine though.

My code is basically a modification of the one provided on this link (
http://www.jbox.dk/sanos/webserver.htm )
which has the same problem as well.

The code to send the data is basically the following (it's my
modification but the original has the same problem) :

while(ftell(file) < length){
    rbytes = fread(buf,1,sizeof(buf),file);
    sbytes = write(newsockfd,buf,rbytes);
}
fclose(file);
close(newsockfd);

Note that I read from the file a predefined number of bytes
sizeof(buf) and then write on the socket the number of bytes read
from the file right after. Sending an exact number of bytes will allow
me to code the bandwidth control later.

It's not a problem of the MIME Headers, as I checked carefully.

I'm running the code on a Slackware 13.1 machine, with no additional patches.

I thought of several things that could cause this such as the Nagle's
algorithm, buffers, glibc, endianness, but I'm not sure.

If you want additional details of the code (besides my code being
something like the link above), please feel free to ask.

Any suggestions will be really appreciated.
--
To unsubscribe from this list: send the line "unsubscribe linux-net" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Netdev]     [Ethernet Bridging]     [Linux 802.1Q VLAN]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Git]     [Bugtraq]     [Photo]     [Yosemite]     [Yosemite News and Information]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux PCI]     [Linux Admin]     [Samba]     [Video 4 Linux]     [Linux Resources]

Add to Google