transfer file's content from server to client side 
Author Message
 transfer file's content from server to client side

Please help:

my server pgm tries to open a file and read the content of the file, then
transer the content to client pgm, here is the code segment:

//server.c
.....
    afile=fopen("test.txt", "r"); //Opens test.txt
    while(c!=EOF) //Checking to see if the character just read is the end of
the file
    {
        c=fgetc(afile); //This reads in the character
        strcat (str,c);   //concatenate each character to a whole string
    }
    fclose(afile); // close the file!

   write(new_sd, str, BUFLEN);
........
//

//client.c
......
while((n=read(sd, bp, bytes_to_read)) >0){
        bp += n;
        bytes_to_read -= n;
    }
.........

1).why i get this error message:
warning: passing arg 2 of `strcat' makes pointer from integer without a cast

and i don't see the stirng stored in str is passed to the client side.
Anything wrong with my pgms?

2). Usually, what method can a server opens a file and transfers the
contents to client pgm?  what functions should i use?

Thank you for your helps!



Sun, 03 Oct 2004 15:48:14 GMT  
 transfer file's content from server to client side

Quote:

> Please help:

> my server pgm tries to open a file and read the content of the file, then
> transer the content to client pgm, here is the code segment:

> //server.c
> .....
>     afile=fopen("test.txt", "r"); //Opens test.txt
>     while(c!=EOF) //Checking to see if the character just read is the end of
> the file
>     {
>         c=fgetc(afile); //This reads in the character
>         strcat (str,c);   //concatenate each character to a whole string
>     }
>     fclose(afile); // close the file!

>    write(new_sd, str, BUFLEN);
> ........
> //

> //client.c
> ......
> while((n=read(sd, bp, bytes_to_read)) >0){
>         bp += n;
>         bytes_to_read -= n;
>     }
> .........

> 1).why i get this error message:
> warning: passing arg 2 of `strcat' makes pointer from integer without a cast

Because strcat doesn't work the way you think it does. strcat
concatenates two strings not a character to a string. You probably want
to read a block of input into your buffer str (well, I actually hope it
is a buffer) and pass that to your networking functions (which isn't what
we're supposed to talk about in this newsgroup). You probably want to
use fread() to read a block of data.

Quote:
> and i don't see the stirng stored in str is passed to the client side.
> Anything wrong with my pgms?

A lot I suppose.

Quote:

> 2). Usually, what method can a server opens a file and transfers the
> contents to client pgm?  what functions should i use?

Off topic in this newsgroup. You either want to take it to
comp.unix.programmer or a special newsgroup for your platform if it isn't
unix (or one of its various flawors).

Quote:

> Thank you for your helps!

--

"LISP  is worth learning for  the profound enlightenment  experience
you will have when you finally get it; that experience will make you
a better programmer for the rest of your days."   -- Eric S. Raymond


Sun, 03 Oct 2004 16:04:48 GMT  
 transfer file's content from server to client side

Quote:
> Please help:
> my server pgm tries to open a file and read the content of the file, then
> transer the content to client pgm, here is the code segment:
> //server.c
> .....
>     afile=fopen("test.txt", "r"); //Opens test.txt
>     while(c!=EOF) //Checking to see if the character just read is the end of
> the file
>     {
>         c=fgetc(afile); //This reads in the character
>         strcat (str,c);   //concatenate each character to a whole string
>     }
>     fclose(afile); // close the file!
>    write(new_sd, str, BUFLEN);
> ........
> //
> //client.c
> ......
> while((n=read(sd, bp, bytes_to_read)) >0){
>         bp += n;
>         bytes_to_read -= n;
>     }
> .........
> 1).why i get this error message:
> warning: passing arg 2 of `strcat' makes pointer from integer without a cast

That's because you're using strcat() wrongly. strcat() concatenates
a string to a string. It does not concatenate a char to a string.
Here's a very simple function to concatenate a char to a string.
char *addchar(char *s, char c) {
  int l=strlen(s);
  s[l]=c; s[l+1]='\0';
  return s;
Quote:
}

Note: If s isn't writable, or does not have space for an additional
char, this function causes undefined behaviour.

Quote:
> and i don't see the stirng stored in str is passed to the client side.
> Anything wrong with my pgms?

This is either a direct result from your strcat() problem or a
socket-related problem. Sockets are off-topic for comp.lang.c.

Quote:
> 2). Usually, what method can a server opens a file and transfers the
> contents to client pgm?  what functions should i use?

Use fopen() and fread() to read the file and some implementation-
specific stuff to transfer the contents to the client.

Quote:
> Thank you for your helps!

--

| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste       W++ B OP+                     |
\----------------------------------------- Finland rules! ------------/
"He said: 'I'm not Elvis'. Who else but Elvis could have said that?"
   - ALF


Sun, 03 Oct 2004 16:05:40 GMT  
 transfer file's content from server to client side


Quote:
> Please help:

> my server pgm tries to open a file and read the content of the file, then
> transer the content to client pgm, here is the code segment:

We'll have to ignore the stuff about "servers", but fortunately you have
a real C problem, so here goeth:

Quote:
> //server.c
> .....
>     afile=fopen("test.txt", "r"); //Opens test.txt

(you should check for a non-null result here. I assume `afile` is properly
declared as a FILE*.)

(don't use // comments; they can wrap badly and compilers that don't
claim to support C99 but do support C89 can toss them out on their ear.
If you want BCPL, you know where to find it.)

Quote:
>     while(c!=EOF) //Checking to see if the character just read is the end of
> the file

What character? You haven't read anything yet. And we need to see what `c`
is declared as, because it matters (it *must not* be any kind of `char`).

[Post complete fragments; the missing pieces may well be the key to the
problem.]

Quote:
>     {
>         c=fgetc(afile); //This reads in the character
>         strcat (str,c);   //concatenate each character to a whole string

No, it does not. `strcat` concatenates a *string* onto another string. That's
why the compiler gives you an error message, as you noted below.

[Even if it worked, it would have quadratic performance. Don't go there
unless you can't avoid it.]

You can have a pointer point into the buffer `str`, eg:

    char *scan = str; /* scan will walk along the buffer */
    ...
    int c = fgetc( afile );
    if (c == EOF) break;
    *scan++ = c;

You'd better be {*filter*}y sure that the buffer won't over-run, of course.
I won't say more about that because the code I sketch below avoids the
issue in a different way.

Quote:
>     }
>     fclose(afile); // close the file!

>    write(new_sd, str, BUFLEN);

What if you've read fewer than BUFLEN characters? [I'm ignoring for the
moment that `write` is not a standard C function.]

Given all that, you'd be better off writing it as

    afile = fopen( ... ); if (afile == 0) ... oops, do something sane ...

    char buffer[BUFLEN];
    while (fgets( buffer, sizeof buffer, afile ))
        write( new_sd, buffer, strlen( buffer ) );

which reads and writes a line at a time, or perhaps even better

    while (1)
        {
        size_t n = fread( buffer, sizeof buffer, 1, afile );
        if (n == 0) break;
        write( new_sd, buffer, n );
        }

which dumps a block at a time and doesn't even care whether afile is
text or not.

Quote:
> 2). Usually, what method can a server opens a file and transfers the
> contents to client pgm?  what functions should i use?

For sending to the client, you have to use a non-Standard-C function
or seven{*filter*}; comp.unix.programmer might well be a better bet.

--
Chris "electric hedgehog" Dollin
C FAQs at: http://www.*-*-*.com/
C welcome: http://www.*-*-*.com/



Sun, 03 Oct 2004 16:40:16 GMT  
 transfer file's content from server to client side

Quote:

>>         strcat (str,c);   //concatenate each character to a whole string
>> 1).why i get this error message:
>> warning: passing arg 2 of `strcat' makes pointer from integer without a cast
>Because strcat doesn't work the way you think it does.

whenever you find yourself using functions you don't know, or you think you
know but which result in these kinds of warnings, you should consult the
documentation that came with your compiler.  if you don't have any you
might consider using <http://www.dinkumware.com/refxc.html>, at least for
standard library functions.

--
bringing you boring signatures for 17 years



Sun, 03 Oct 2004 20:07:20 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Raise event from client side on server side, passing parameter

2. Server Side and Client Side Scripting in ASP.NET

3. Client side v/s Server side

4. File transfer between client/server

5. Client Side Validation preventing client side script from running

6. Sockets - Detecting client closure from server side

7. please help to configure DCOM in both Server and client side

8. Is there a way to debug Vb client/ATL Server where use debuggers BOTH sides

9. DCOM question.. choose server from client side

10. Client identification at server side in DCOM object

11. ASP.NET: adding client-side attributes to webform server control

12. Need COM advice on 16 server/ 32 client with large data transfers

 

 
Powered by phpBB® Forum Software