Thread: Function in a Server program

  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, 11:45 AM
  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, 10:00 AM
  5. qt help
    By Unregistered in forum Linux Programming
    Replies: 1
    Last Post: 04-20-2002, 09:51 AM