By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,919 Members | 1,587 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,919 IT Pros & Developers. It's quick & easy.

Client-Server communication problem with mailslot

P: n/a
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.
Aug 7 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"Alhazred" <a.********@email.itwrites:
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[i] = (char)ch;
MyMessage[i]='\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.
Aug 7 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.