Client-Server communication problem with mailslot

Discussion in 'C Programming' started by Alhazred, Aug 7, 2007.

  1. Alhazred

    Alhazred Guest

    I'm writing a client-server software which should emulate an email service
    on a local machine. I'm now at the beginning and I'm trying to let
    communicate the client and the server process, but have a problem with
    GetMailslotInfo() in the server process inside the main() which returns with
    error code 1 which means "Invalid Function" though it looks correct to me.

    Can you understand why does that happen?

    You can see the code here:
    http://lacasa.altervista.org/software/Server_01.c
    http://lacasa.altervista.org/software/Client_01.c
    http://lacasa.altervista.org/software/input.txt
    the last one must be inside the folder where you put the server process and
    it is needed to use the "Read email" option.

    That host doesn't support direct linking, then you have to copy and paste
    the links into the browser address bar.
     
    Alhazred, Aug 7, 2007
    #1
    1. Advertising

  2. "Alhazred" <> writes:

    > I'm writing a client-server software which should emulate an email service
    > on a local machine. I'm now at the beginning and I'm trying to let
    > communicate the client and the server process, but have a problem with
    > GetMailslotInfo() in the server process inside the main() which returns with
    > error code 1 which means "Invalid Function" though it looks correct
    > to me.


    You will have to ask in a Windows group about why GetMailslotInfo is
    returning an error. This group deals with standard C.

    > You can see the code here:
    > http://lacasa.altervista.org/software/Server_01.c
    > http://lacasa.altervista.org/software/Client_01.c


    I was looking to see if this was indeed Windows code, and I saw:

    for( i = 0; (i < 99) && ((ch = getchar()) != EOF) && (ch != '\n'); i++ )
    MyMessage = (char)ch;
    MyMessage='\n'; // ritorno a capo
    MyMessage[i+1] = '\0'; // termina la stringa
    strcpy (request_message.req.da, MyMessage);

    (and this pattern is repeated several times). The buffer MyMessage
    and request_message.req.da are all arrays of size 100.

    This is a convoluted way to put line from stdin into a buffer and in
    all the convolution you have introduced a serious error. When the
    input is long, the loop can terminate with i == 99. MyMessage[i+1]
    invokes undefined behaviour when i == 99.

    Every time you write a loop (for, while, do), invert the condition and
    then look to make sure that the code following makes sense in all of
    the cases that might terminate the loop:

    !((i < 99) && ((ch = getchar()) != EOF) && (ch != '\n'))

    implies that i == 99 or ch == EOF or ch == '\n' at the loop exit.

    [Aside: your 99 should be calculated from the macro used to define the
    arrays: MAX_DIMENSION - 1 and it should be '- 2' rather than '- 1', of
    course].

    Also, the above code is trying to do what the one line:

    fgets(request_message.req.da, MAX_DIMENSION, stdin);

    does.

    --
    Ben.
     
    Ben Bacarisse, Aug 7, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Russ
    Replies:
    1
    Views:
    584
    =?Utf-8?B?Q2hhcmxlcyBDaGVu?=
    Nov 29, 2004
  2. Michelle
    Replies:
    2
    Views:
    435
    Michelle
    Jul 19, 2004
  3. Replies:
    3
    Views:
    795
  4. Dustin
    Replies:
    2
    Views:
    1,082
    G. S. Hayes
    Aug 9, 2004
  5. Bruce

    client-to-client communication via SOAP

    Bruce, Mar 21, 2005, in forum: ASP .Net Web Services
    Replies:
    3
    Views:
    273
    [MSFT]
    Mar 28, 2005
Loading...

Share This Page