Networking Forums

Networking Forums > Computer Networking > Linux Networking > Why am I getting extra bytes?

Reply
Thread Tools Display Modes

Why am I getting extra bytes?

 
 
Mark0978@gmail.com
Guest
Posts: n/a

 
      06-20-2007, 12:52 PM
I must have lost my mind because I cannot for the life of me see why
this is happening. I'm on linux 2.6, gcc compiler and code that is
too simple to be playing tricks like this.

The server reports:
Read 216809472 Bytes, Wrote 216809472 Bytes for 'longmetro05.raw'

The client reports:
Read 216809479 bytes, Wrote 216809479 bytes to 'longmetro05.raw'

Please point out how stupid I am and where the problem is.

Here is the client code:
int nTotalRead = 0, nTotalWritten = 0;
while(1) {
int nRead = read(socketfd, buf, sizeof(buf));
nTotalRead += nRead;
if(nRead > 0) {
int nWritten = write(fd, buf, nRead);
//printf("%d - %d\n", startat, nWritten);
nTotalWritten += nWritten;
if(nWritten != nRead) {
fprintf(stderr, "Error writing '%s'", argv[2]);
exit(-3);
}
} else if(nRead == 0) {
// Connection closed by other end
close(fd);
break;
} else if(nRead < 0) {
close(fd);
perror("Error reading socket");
exit(-4);
}
}

printf("Read %d bytes, Wrote %d bytes to '%s'\n", nTotalRead,
nTotalWritten, argv[2]);

Here is the server code:

int nTotalRead = 0, nTotalWritten=0;
while(1) {
int nRead = read(fd, bufr, sizeof(bufr));
nTotalRead += nRead;
if(nRead) {
lastOffset = lseek(fd, 0, SEEK_CUR);
int nWritten = write(pInfo->clientfd, bufr, nRead);
nTotalWritten += nWritten;
//printf("%d - %d\n", lastOffset, nWritten);
while(nWritten != nRead) {
fd_set writefds, exceptfds;
struct timeval timeout = {5, 500000};

FD_ZERO(&writefds); FD_ZERO(&exceptfds);
FD_SET(pInfo->clientfd, &writefds); FD_SET(pInfo->clientfd,
&exceptfds);

int nSelected = select(pInfo->clientfd+1, NULL, &writefds,
&exceptfds, &timeout);
if(nSelected) {
if(FD_ISSET(pInfo->clientfd, &writefds)) {
int nWrote = write(pInfo->clientfd, &bufr[nWritten], nRead-
nWritten);
//printf("%d %d\n", lastOffset, nWrote);
nWritten += nWrote;
nTotalWritten += nWrote;
}
} else {
if(FD_ISSET(pInfo->clientfd, &exceptfds)) {
close(fd);
return -10; // Exit thread
}
}
}
} else {
printf("Read %d Bytes, Wrote %d Bytes for '%s'\n", nTotalRead,
nTotalRead, cmd);
//We are finished
close(fd);
return -10;
}
}
}

 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
The reason behind 576 bytes karthikbalaguru Linux Networking 2 03-18-2008 05:01 PM
bytes sent & bytes received ... tarzan Broadband 6 09-16-2005 03:09 PM
300K bytes per second on MN-500 Jason Lu Broadband Hardware 5 08-12-2004 11:31 AM
Extra bytes in packets allan Linux Networking 1 01-19-2004 11:41 AM
[HELP] data corruption: swap of bytes distant from 12 bytes Francois Grieu Windows Networking 0 11-17-2003 07:57 AM



1 2 3 4 5 6 7 8 9 10 11