Function in a Server program

This is a discussion on Function in a Server program within the C Programming forums, part of the General Programming Boards category; Hi to All, I have written a little server that work fine. Now I need to add a function in ...

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    26

    Function in a Server program

    Hi to All,

    I have written a little server that work fine.
    Now I need to add a function in the main that process a phrase, passed from a client as telnet. The last part of main is:

    Code:
    listen(sock, 1);
    /* connection client */
    while (1) {
    client_len = sizeof(client);
    if ((fd = accept(sock, (struct sockaddr *)&client, &client_len)) < 0) {
    perror("accepting connection");
    exit(3);
    }
    fprintf(stderr, "The connection is Open.\n");
    send(fd, "Wellcome in my Server !\n\n", 38, 0);
    send(fd, "Please send Your Phrase, terminated by ..)!\n\n", 44, 0);
    process_phase(fd,fd);
    close(fd);
    fprintf(stderr, "The Connection is Closed.\n");
    }
    fd is the socket descriptor and the function is like:
    void process_phrase(int in, int out);

    How must write the code that read the phrase until the client send the terminator signal ".."

    I hope in Your help. I am a newbie in C programming.

    Thank You and Best Regards.
    Nick

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    In a word: Beej

    Read, compare, do something appropriate.


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 12:45 PM
  2. Server Architecture
    By coder8137 in forum Networking/Device Communication
    Replies: 2
    Last Post: 01-29-2008, 11:21 PM
  3. Server Client Messaging Program
    By X PaYnE X in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-04-2004, 05:20 PM
  4. I need help with passing pointers in function calls
    By vien_mti in forum C Programming
    Replies: 3
    Last Post: 04-24-2002, 11:00 AM
  5. qt help
    By Unregistered in forum Linux Programming
    Replies: 1
    Last Post: 04-20-2002, 10:51 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21