Solved

send buffer

Posted on 2011-03-25
67
583 Views
Last Modified: 2012-06-21
hi all,
 Right now, my code is limited to send text data only due to my sendMessage() . Third argument is string type. So I need to rework to transfer buffer instread of string.

>>Couldn't this sendMessage() call another function which is char * oriented? And when you actually have char * as in Message 3, then just use the lower level fuction.

Before sendMessage() can call another function, we already pass string to sendMessage() !!! Or should i change the third argument to char * ? so handle message1, message2 need to change, but message3 is ok to send.


>> If the String uses the Z-terminator common to C, you'll have lost the length before you get to a character based object.
 Can u elaborate more? tks.
client.c
server.c
0
Comment
Question by:BeginToLearn
  • 32
  • 26
  • 8
67 Comments
 
LVL 45

Expert Comment

by:Kdo
ID: 35216043
Hi Begin,

Change the third argument to char*.  You'll also want to pass the length of the object that you intend to send.


Kent
0
 

Author Comment

by:BeginToLearn
ID: 35216573
>>You'll also want to pass the length of the object that you intend to send.

did u mean size of object to send  because of sending object?  
0
 

Author Comment

by:BeginToLearn
ID: 35216960
I made change to sendMessage () . It receive char * and objectlen now. After I run debug on client ( ignore server side), i see no error here. Could you please point any hidden error in it? I just want to make sure my logic is correct before working on server. tks.

client.c
0
 
LVL 45

Expert Comment

by:Kdo
ID: 35217143
Hi Begin,

It looks rational.  Give it a try.....


Kent

0
 

Author Comment

by:BeginToLearn
ID: 35217251
isegmentation fault. I am on debugging process. In sendOneFile,
    strcpy(tmp, t.c_str());
      int len= strlen(tmp);
      printf("in sendOneFile, len is %d\n",len);
        //sending message2 -> [size_of_message][2][filename delimeter filesize]
        sendMessage( sock, message_id,tmp, strlen(tmp) );

in sendOneFile, len is 33
in sendOneFile, len is 34

so I need to find out why. It should consistent
0
 

Author Comment

by:BeginToLearn
ID: 35217319
in message1, len is 1
in message2, len is 33
in message3, len is 2048
in message3, len is 2048
in message3, len is 2048
in message3, len is 2048
in message3, len is 2048
in message3, len is 2048
in message3, len is 2048
in message3, len is 2048
in message3, len is 2048
in message3, len is 2048
in message3, len is 2048
in message3, len is 2048
in message3, len is 960
in message2, len is 34

after using calculate , sum of messag3 = 25536. It matches with the size of "client" file. However the size of file "client 25536" is 26637.
It tells me something is wrong at server receiving in writing . let me check server side.
0
 
LVL 45

Expert Comment

by:Kdo
ID: 35217389
Ok.  Let's dissect the source.  :)

It looks like you're trying to sent the string object t, then loop on the file with fread.


Kent
0
 

Author Comment

by:BeginToLearn
ID: 35217688
due to general file type, I need to update fread to rb mode, and fwrite rb mode hihi. (i got those info from other comments) then i can start debug process again.
0
 
LVL 45

Expert Comment

by:Kdo
ID: 35217732
Yeah.  I read those comments and agree.

Quite frankly, I didn't even check the open mode.  It's so automatic to me that I didn't even check the fine print in your fopen statement.

Fortunately, it's a very small change.  
0
 

Author Comment

by:BeginToLearn
ID: 35217841
just in case my code is needed, i post them
client.c
server.c
0
 

Author Comment

by:BeginToLearn
ID: 35218167
I just realized that in receiveMessage() i forgot to update. Right now it return string, let me change it to return char * so it can be use directly in fwrite. hope this cause problem hihihi
0
 

Author Comment

by:BeginToLearn
ID: 35218306
// receiving message3-> [size_of_message][3][data]
      // keep receiving and appending to file. use the message[2] data to determine when loop stops
      unsigned int nread =0;
      while( nread < itssize )
        {
              char *t= receiveMessage(sock);
            
            int result= fwrite (t,1,sizeof(t),fp);  <<< wrong !!!!
                if( result != sizeof(t))
                {      
                      error("writing error\n");
                }
                memset(t,'\0',BUFFER_LEN);
                nread = nread + result;
         }  

I know the int result= fwrite (t,1,sizeof(t),fp) wrong because sizeof(t) is just sideof char. However, i want the size of whole array which t point to. So please advise. tks.
0
 
LVL 32

Expert Comment

by:phoffric
ID: 35218879
You changed sendMessage api to deal with binary files.

Your fwrite needs the received message content to write to the disk, and you need to know how many bytes to write. The receiveMessage function has this information. So change the receiveMessage api so that the caller has access to that information.

Give it a try, run, debug, and let us know if you get stuck.
0
 

Author Comment

by:BeginToLearn
ID: 35219102
I just got to work. I knew I need those infofor fwrite,but didnt think of change receivemessage. Tks.if u can,pls let me know specific what change in receivemessage fn  so when I get home at 10:30 I can work immediately.tks a lot
0
 

Author Comment

by:BeginToLearn
ID: 35219112
Feeling I am very very close to make it work
0
 
LVL 32

Expert Comment

by:phoffric
ID: 35219153
While you are at work, just think about it. From all your posts, I know you know how have a function fill an array and return an integer to the caller.

You latest post is very close to a working solution. FYI - in your last code of the previous question, a little tweaking and all files transferred well (in size and in content - including .exe files).
0
 

Author Comment

by:BeginToLearn
ID: 35219230
Omg I am so close to it.really want to get get home to work on it.i work with customer .thats y I cant access computer.r u available late tonite or early morning tommorrow?tks
0
 
LVL 32

Expert Comment

by:phoffric
ID: 35219261
It's 5:30pm here. Probably be here at least 5-6 more hours. How early tomorrow are you talking?
0
 

Author Comment

by:BeginToLearn
ID: 35219534
Around 8 am at ur place bc I can wake up at 5 am  at my  place
0
 
LVL 32

Expert Comment

by:phoffric
ID: 35219682
Not sure I'll be there at 8am (I hope to catch up on some z's). But don't worry, there are plenty of others in Europe who will gladly help, and as early as 1:30 am my time, some start to show up. Maybe kdo will also be back. You are so close. Again, to get their attention, you can always ask a specific question as to what problem you are having.

I'm going to say two things that you should ignore until you get all the functionality working:
The server is getting the message_id, but it is not doing anything with it. Try to figure out something useful to do with it now that you took a lot of trouble to obtain it (and hopefully a lot of good experience learning).
I notice you are zeroing out buffers more than you need to. You should critique each usage of this and ask whether you are doing something that is absolutely required. Again, get all your functionality working first.
0
 

Author Comment

by:BeginToLearn
ID: 35220424
I have 1 idea .either have global variable or a function is activated by meesassage id 3.it will hold value of data in meaaafe 3 .before using fwrite,use that value to know how many bytes to write.am I right?
0
 
LVL 32

Expert Comment

by:phoffric
ID: 35220599
Global variables are always an easy way to solve an immediate problem of passing information from one function to another without having to worry about the interface. If that approach helps you then go for it.

Caveat: global variables are considered bad form.

In the client, you managed to be able to pass the buffer content and the number bytes to send; in the server, you should be able to pass the information from the function to the caller. Here are links for you to read before you decide what path you wish to take:

http://www.learncpp.com/cpp-tutorial/73-passing-arguments-by-reference/

http://publib.boulder.ibm.com/infocenter/comphelp/v7v91/index.jsp?topic=%2Fcom.ibm.vacpp7a.doc%2Flanguage%2Fref%2Fclrc07cplr233.htm

http://rdsrc.us/38qblN

http://rdsrc.us/6Hfpi7

http://rdsrc.us/GrKUyf



I'm signing off for now. See you around 8-9am (your time).
0
 
LVL 32

Expert Comment

by:phoffric
ID: 35220622
Between globals and the approach described in the links, there is another way, which will become obvious (once you get some rest). So, there are multiple ways to work this problem. Given the level of difficulty of your project, the solution to this should be easy. Just do what makes sense to you at this time.
0
 

Author Comment

by:BeginToLearn
ID: 35220909
After reading all link, i decide to use pass reference method because i want my code have all functions reusable in future. FOr the first 4 times, it worked ok. Then screw up after that. haiz

I have a very weird message in terminal. I post both sever and client in order to follow it easily.


ubuntu@ubuntu:~/program$ ./client
Current working dir: /home/ubuntu/program
in message1, len is 1
in message2, len is 33
in message3, len is 2048
in message3, len is 2048
in message3, len is 2048
in message3, len is 2048
in message3, len is 2048
in message3, len is 2048
in message3, len is 2048
in message3, len is 2048
in message3, len is 2048
in message3, len is 2048
in message3, len is 2048
in message3, len is 2048
in message3, len is 960
in message2, len is 34
in message3, len is 2048
in message3, len is 2048
ubuntu@ubuntu:~/program$

--------------------------------------------------
ubuntu@ubuntu:~/program$ ./server
writing : result is 2048
writing : result is 2048
writing : result is 2048
writing : result is 2048
writing : result is 2049
writing : result is 2049
writing : result is 2049
writing : result is 2049
writing : result is 2049
writing : result is 2049
writing : result is 2049
writing : result is 1977
writing : result is 56
writing : result is 960
writing : result is 34
*** stack smashing detected ***: ./server terminated
======= Backtrace: =========
/lib/libc.so.6(__fortify_fail+0x50)[0x27b970]
/lib/libc.so.6(+0xe591a)[0x27b91a]
./server[0x8048f51]
[0x3b647473]
======= Memory map: ========
00170000-00194000 r-xp 00000000 08:01 2360651    /lib/libm-2.12.1.so
00194000-00195000 r--p 00023000 08:01 2360651    /lib/libm-2.12.1.so
00195000-00196000 rw-p 00024000 08:01 2360651    /lib/libm-2.12.1.so
00196000-002ed000 r-xp 00000000 08:01 2360647    /lib/libc-2.12.1.so
002ed000-002ef000 r--p 00157000 08:01 2360647    /lib/libc-2.12.1.so
002ef000-002f0000 rw-p 00159000 08:01 2360647    /lib/libc-2.12.1.so
002f0000-002f3000 rw-p 00000000 00:00 0
008b5000-008b6000 r-xp 00000000 00:00 0          [vdso]
00a87000-00aa1000 r-xp 00000000 08:01 2354767    /lib/libgcc_s.so.1
00aa1000-00aa2000 r--p 00019000 08:01 2354767    /lib/libgcc_s.so.1
00aa2000-00aa3000 rw-p 0001a000 08:01 2354767    /lib/libgcc_s.so.1
00ac5000-00ba4000 r-xp 00000000 08:01 1311830    /usr/lib/libstdc++.so.6.0.14
00ba4000-00ba8000 r--p 000de000 08:01 1311830    /usr/lib/libstdc++.so.6.0.14
00ba8000-00ba9000 rw-p 000e2000 08:01 1311830    /usr/lib/libstdc++.so.6.0.14
00ba9000-00bb0000 rw-p 00000000 00:00 0
00eff000-00f1b000 r-xp 00000000 08:01 2360642    /lib/ld-2.12.1.so
00f1b000-00f1c000 r--p 0001b000 08:01 2360642    /lib/ld-2.12.1.so
00f1c000-00f1d000 rw-p 0001c000 08:01 2360642    /lib/ld-2.12.1.so
08048000-0804b000 r-xp 00000000 08:01 1837228    /home/ubuntu/program/server
0804b000-0804c000 r--p 00002000 08:01 1837228    /home/ubuntu/program/server
0804c000-0804d000 rw-p 00003000 08:01 1837228    /home/ubuntu/program/server
0904a000-0906b000 rw-p 00000000 00:00 0          [heap]
b78a9000-b78ac000 rw-p 00000000 00:00 0
b78b7000-b78b8000 rw-p 00000000 00:00 0
b78b9000-b78bb000 rw-p 00000000 00:00 0
bfe55000-bfe76000 rw-p 00000000 00:00 0          [stack]
Aborted
ubuntu@ubuntu:~/program$


client.c
server.c
0
 
LVL 45

Expert Comment

by:Kdo
ID: 35222162
Hi Begin,

The biggest issue seems to be in the data that you're passing and how it's being handled.

The second biggest issue is that you're getting too much advice from too many directions.  (It's all good advise, but sometimes it contradicts a bit.  Apologies...)  It's making things more complicated than they have to be.

Look at the first few lines from the client trace:

ubuntu@ubuntu:~/program$ ./client
Current working dir: /home/ubuntu/program
in message1, len is 1
in message2, len is 33
in message3, len is 2048

You send the file count as an ASCII formatted value.  (Lines 150 - 160 in client.c)


Now look at the first few lines from the server trace:

ubuntu@ubuntu:~/program$ ./server
writing : result is 2048
writing : result is 2048

You don't really trace the read of the control information.  Let's dissect.

Main calls receiveTotalFiles (@ 202)
   -- calls receiveMessage (@ 150) passing -1 as the length.
   -- calls read (@ 40), passing sizeof (size_to_read) as the length.

So it appears that your client program formats the number of files into an ASCII string and sends the string.  The server program is expecting a binary integer.

The data coming from the client is file count / file name / data.  When sending only one file, the data sent by the client could be:

1 C:\Temp\myfile
1 myfile.txt
1 1stop.log

In any case, what the server receives is 1C:\, 1myf, or 11st as the file count.


Get rid of the string encapsulator for the integer values!  You're sending explicit data.  A count is an integer.  Send an integer.  A file name is a string.  Send a length value and the string, or send a string and a terminator.  If you send the string and terminator the server program will have no way to know how long the name is so you'll read a full buffer, pull the name out of the buffer, and probably still have data in the buffer that will need to be written to the file.


Kent
0
 

Author Comment

by:BeginToLearn
ID: 35222204
i am reading it carefully now .
0
 
LVL 45

Expert Comment

by:Kdo
ID: 35222220

Hi Begin,

I know that this exercise is a learning experience (and quite the experience it has become) but think simply.  You're sending data, you're receiving data.  Everything else is support for those functions.


Kent
0
 
LVL 32

Accepted Solution

by:
phoffric earned 300 total points
ID: 35222373
Hi Begin,

Your new api for receiveMessage is an improvement (though, I would have swapped the two additions you made to the api).

I do have a question about some code inside of receiveMessage:
1)    n = read( sock, & size_to_read, sizeof( size_to_read)); // where are you using size_to_read?
2)    int len= strlen(pch);                // why strlen? And how are you using the specific value len?
3)    if(n < (sizeof (char)*len))        // ?? please explain what you are testing ? Hard to read.
0
 

Author Comment

by:BeginToLearn
ID: 35222457
Do you mean I should use size_to_read in // receiving size_of_message in // receive data because i haven't used that info?  
0
 
LVL 32

Expert Comment

by:phoffric
ID: 35222484
I'm wasn't telling you what to do. I was just looking over your code and had some questions about your code.
0
 

Author Comment

by:BeginToLearn
ID: 35222517
hihi. I didn't use the size_to_read at all. Also, the len is used to see the length of data receiving in to pch. an that n< sizeof(char)*len is used to determine how many bytes it received in phc.

I can see something wrong here!!!!
0
 
LVL 32

Expert Comment

by:phoffric
ID: 35222600
Ok, here's a tip in writing code. Whenever you define a variable, give a clear comment definition of what it means and/or how it is to be used.

BTW - if you do this, your instructor may be happier.
0
 

Author Comment

by:BeginToLearn
ID: 35222604
i reworked on receiveMessage()

char* receiveMessage(SOCKET sock, int & sizedata)
{
        unsigned int size_to_read= 0, message_id = 0;
        string a;
      int n;
      
      // receive size_of_message
      n = read( sock, & size_to_read, sizeof( size_to_read));
      if( n != (int) sizeof( unsigned int))
        {
            error(" received wrong size_to_read");
        }      
      //receive message_id
        n = read( sock, & message_id, sizeof( message_id));
      if( n != sizeof( unsigned int))
      {
            error("receive wrong message_id");
      }
       //receive data
      static char  pch[BUFFER_LEN]= {'\0'};
      n = read( sock, pch, size_to_read);
      sizedata = n;
      if(n < size_to_read)
      {      
            error("Error in receiving data buffer");
      }
      return pch;
}

A little bit closer to work.

ubuntu@ubuntu:~/program$ ./server
writing : result is 2048
writing : result is 2048
writing : result is 2048
writing : result is 2048
writing : result is 2048
writing : result is 2048
writing : result is 2048
writing : result is 2048
writing : result is 2048
writing : result is 2048
writing : result is 2048
Error in receiving data buffer: Success

ubuntu@ubuntu:~/program$ ./client
Current working dir: /home/ubuntu/program
in message1, len is 1
in message2, len is 33
in message3, len is 2048
in message3, len is 2048
in message3, len is 2048
in message3, len is 2048
in message3, len is 2048
in message3, len is 2048
in message3, len is 2048
in message3, len is 2048
in message3, len is 2048
in message3, len is 2048
in message3, len is 2048
in message3, len is 2048
in message3, len is 960

0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 32

Expert Comment

by:phoffric
ID: 35222616
>> Error in receiving data buffer: Success
What is causing this error message?
0
 
LVL 32

Expert Comment

by:phoffric
ID: 35222619
I see that Kdo mentioned (in a paraphrase) "Too Many Cooks in the Kitchen Spoil the Broth".
I agree that all the good advice (but in different directions) may have caused some confusion.

With that thought in mind, and since Kdo explains things so well, shall we agree that for this question, Kdo should finish up?
0
 

Author Comment

by:BeginToLearn
ID: 35222625
No please. I learn a lot from all experts. The most important part is leaning skill. I am working on
 >> Error in receiving data buffer: Success
I think it related to receiving because sending is ok.
0
 

Author Comment

by:BeginToLearn
ID: 35222705
Totally weird !!! I just add 2 files to display comment . and now it's work!!!!!!!!!!!!!!!!

I have no idea hix hix hix.
0
 
LVL 45

Expert Comment

by:Kdo
ID: 35222732

Hi Begin,

I don't know what you mean by "add 2 files to display comment".  Can you repost your source (again).


Kent
0
 
LVL 32

Expert Comment

by:phoffric
ID: 35222733
When you add something that makes it work that is not good. There is something wrong.
Here's what I got with http:#35222604 function replacement:

writing : result is 1748
      7 [main] svr 2760 exception::handle: Error while dumping state (probably corrupted stack)
Segmentation fault (core dumped)


For debug, for every send, there is a receive, so make the debug match on both sides.

ubuntu@ubuntu:~/program$ ./client
Current working dir: /home/ubuntu/program
in message1, len is 1
in message2, len is 33
in message3, len is 2048


ubuntu@ubuntu:~/program$ ./server
writing : result is 2048
writing : result is 2048
writing : result is 2048

Since debug in client has "message1", debug in server should have same notation.
The numbers on both sides should match if you mirror the debug properly.
0
 

Author Comment

by:BeginToLearn
ID: 35222752
my code here. Let me take a deep breath about them. I don't want my code work randomly or without understand it . Sometimes working is not a good solution for me . So please help me .
client.c
server.c
0
 
LVL 32

Expert Comment

by:phoffric
ID: 35223020
What progress have you made?

You want the debug to match. Try to get mirror images of debug statements and no extra lines.

For message 1, just include number of files
For message 2, just print out filename
For message 3, just print out len
0
 
LVL 45

Assisted Solution

by:Kdo
Kdo earned 200 total points
ID: 35223031
Hi Begin,

I'm here.  (I'll be out a little while later, but not for long.)

Let's recap:

Each message consists of three fields:
  1.  Data Length.
  2.  Block Type.
  3.  Data.

I'd have swapped the first two items, but that's just personal preference.  (It could make life a little easier if you expand the program as you could easily have a message type that doesn't require data.  In that case, you could send just the message_id instead of 0 and the message_id.)  Let's keep it as is for now.  If you want to change that later it will be very easy once the program is correct.

SendMessage and receiveMessage each need to only follow that model for reasonable communications.  In fact, you pass those three items to sendMessage (along with the socket).  So the task is making sendFile flow in a logical and understandable fashion.  The same principal should apply to receiveMessage and the other server functions.

There's no need to scope the variables within any of these functions.  Many of the older C compilers won't even let you do this.


I've simplified the sendOneFile function and included it below.  The variables are all declared at the function, and changes are noted.  Some of the variables are no longer needed, but I've left them anyway.

Remove the IN and OUT comments, and the function is about 1/2 the length of the original, and much easier to follow.

Note that it really does need a couple of small improvements still.  Message types 2 and 3 are constants that are put into an integer variable before being passed to sendMessage.  The function codes really need to be an enumeration and the message type passed to the sendMessage function by passing the name of the message type.

enum
{
  MSG_FILENAME=2,
  MSG_DATA=3
}

e.g.

  sendMessage (sock, MSG_FILENAME, buffer, length);

The second parameter to sendMessage (message type) is declared as an integer so the sendMessage function will always pass the 4 byte integer value.



Kent


void sendOneFile( SOCKET sock, string filename)
{
  FILE *fp;
  int result = -1;
  int filesize;
	unsigned int message_id;
  char *buffer;
  int BlockLength;  
  int len;
  int n;
  unsigned int size_to_read;
	
  fp= fopen(filename.c_str(),"rb");// t is the filename string

  if(fp == NULL)
  { 
    error(filename.c_str());
    exit(1);
  } 

// determine file size 
  fseek(fp, 0, SEEK_END);
  filesize = ftell(fp);
  rewind(fp);

// IN (start)
  buffer = (char*)malloc (BUFFER_SEND);
// IN (end)

//OUT        string t = filenameSpacefilesize(filename, filesize);
      
  message_id = 2;
	
//OUT        strcpy(tmp, t.c_str());
//OUT	int len= strlen(tmp);

  printf("in message2, len is %d\n",len);
//sending message2 -> [size_of_message][2][filename delimeter filesize]
  sendMessage( sock, message_id,filename.c_str(), filename.length());
//OUT.        memset(tmp, '\0',sizeof(tmp)/sizeof(tmp[0])) ;
              
//OUT.        char buffer[BUFFER_LEN]={'\0'} ; 
//OUT        int BlockLength;
  message_id = 3;
  while ((result= fread (buffer, 1, BUFFER_SEND, fp)) > 0)
  {
//OUT		int n;
    printf("in message3, len is %d\n",result);
//sending message3 -> [size_of_message][3][data]
    sendMessage( sock, message_id, buffer, result );
//OUT	  memset(buffer, '\0',sizeof(buffer)/sizeof(buffer[0])) ;// reset buffer after sending
//OUT 	memset(tmp, '\0',sizeof(tmp)/sizeof(tmp[0])) ;
  }
  fclose(fp);
}

Open in new window

0
 
LVL 32

Expert Comment

by:phoffric
ID: 35223086
If you mirror the debug as suggested, then you should be able to see a problem. I did this ...

I did something where your program works on the first run, but starts to show a bad sign on the 2nd and 3rd run; and really looks bad on the 4th run.
0
 

Author Comment

by:BeginToLearn
ID: 35223100
Srry. I just hangup the phone because a friend informed a bad news. A another friend whose daughter (3 yrs old) just passed away due to defected heart valve.

Let me focus again.  One debugging as you suggest:
    For message 1, just include number of files
    For message 2, just print out filename    
    For message 3, just print out len
0
 
LVL 32

Expert Comment

by:phoffric
ID: 35223114
Very sorry about the bad news. That is extremely sad for your friend. I thought heart valve replacement was often successful.
0
 

Author Comment

by:BeginToLearn
ID: 35223130
Stanford hospital planned to do bypass surgery on april 24. Her valve diameter is around 1 mm , in compare to regular size 3 mm. Sometime we never know.

Anyway, let me work on debugging again because i go to work around 3:15 pm
0
 

Author Comment

by:BeginToLearn
ID: 35223216
No luck this time for first run. From below terminal message :

in message3, len is 2048
writing : result is 2048
n is 2048 and size_to_read is 2048
in message3, len is 2048
writing : result is 2048
n is 1984 and size_to_read is 2048
Error in receiving data buffer: Success

It receives wrong size. Let me review client side.

0
 
LVL 32

Expert Comment

by:phoffric
ID: 35223262
Recall that n can be less than what you expected without an error. That could be timing related.

If you step carefully in the debugger so that the client sends a message, and then you step over the read, do you still have the problem?
0
 
LVL 32

Expert Comment

by:phoffric
ID: 35223279
>> Error in receiving data buffer: Success
Ever wonder why perror is claiming Success when you are claiming an error?
0
 
LVL 32

Expert Comment

by:phoffric
ID: 35223291
ref: http://linux.die.net/man/2/read

Return Value
...
It is not an error if this number is smaller than the number of bytes requested
...
On error, -1 is returned, and errno is set appropriately
0
 

Author Comment

by:BeginToLearn
ID: 35223295
i guess SUCCESS means successful to terminal the program. Let me read
       ref: http://linux.die.net/man/2/read carefully.
0
 

Author Comment

by:BeginToLearn
ID: 35223300
read() attempts to read up to count bytes from file descriptor fd into the buffer starting at buf.
0
 
LVL 32

Expert Comment

by:phoffric
ID: 35223303
Given that you successfully modified the api of the receiveMessage function, it sounds like you are having other issues. Do you think we should move onto another question?
0
 
LVL 32

Expert Comment

by:phoffric
ID: 35223321
>> fp = fopen(fn, "ab");
Why do you open using "ab"?
0
 

Author Comment

by:BeginToLearn
ID: 35223334
i use "ab" for binary file. Let me open a new question bc this is too long
.
 
0
 
LVL 32

Expert Comment

by:phoffric
ID: 35223335
That explains the "b" - oK
Why the "a" ?
0
 

Author Comment

by:BeginToLearn
ID: 35223343
a is appending. I combine both "ab" mean binary appending.
        http://www.cprogramming.com/tutorial/cfileio.html
0
 
LVL 32

Expert Comment

by:phoffric
ID: 35223345
Ok, if that is intentional that you want to append. Just curious, why append rather than create a new file using "wb"?
0
 

Author Comment

by:BeginToLearn
ID: 35223356
oh because we mention about diff something. So I want to leave it open for later . If any change occur, only update the difference.
0
 
LVL 32

Expert Comment

by:phoffric
ID: 35223363
In the folder where you run your client and server, could you show the result of:
 ll -R
0
 
LVL 32

Expert Comment

by:phoffric
ID: 35223366
I mean
ls -R -l
0
 

Author Comment

by:BeginToLearn
ID: 35223389
after close the debugger and delete the "filename and itssize", and run ls -R -l
message is below

ubuntu@ubuntu:~/program$ ls -R -l
.:
total 184
-rwxr-xr-x 1 ubuntu ubuntu 83432 2011-03-26 12:17 client
-rw-r--r-- 1 ubuntu ubuntu  5920 2011-03-26 12:16 client.c
-rwxr-xr-x 1 ubuntu ubuntu 47868 2011-03-26 12:16 server
-rw-r--r-- 1 ubuntu ubuntu  5727 2011-03-26 12:15 server.c
-rwxr-xr-x 1 ubuntu ubuntu 28706 2011-03-21 01:27 test
-rw-r--r-- 1 ubuntu ubuntu  3356 2011-03-21 01:29 test.c
ubuntu@ubuntu:~/program$

0
 
LVL 32

Expert Comment

by:phoffric
ID: 35223398
Ok, I guess you are creating the files in another folder. I was creating in the same folder. Just wondering - if you look at the server creation folder, is all OK there?
0
 

Author Comment

by:BeginToLearn
ID: 35223409
oh nope. Both of them create in same folder which is /program. that's why i "filename itsize" to distinguish original one and new one while testing
0
 
LVL 32

Expert Comment

by:phoffric
ID: 35223426
Ok, then we're looking at the same thing. I didn't see any new filenames, so I thought you were creating them elsewhere.

>> because we mention about diff something. So I want to leave it open for later .
I don't understand what your requirement is. Please clarify.

I have been using diff to verify that the contents of the created file is identical to the original file.
0
 

Author Comment

by:BeginToLearn
ID: 35223444
i  deleted the "filename and itssize" before run that command. the requirement is just transfer files and subfolder. This is the project1. After spring break, i will get project2 which based on project1.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now