Вопрос

I wrote a simple server-client program in which server and client are communicating using named pipes.Everything is working fine,but i have a simple question: In the client part i allocate the msg that is going to be sent to the server in this way char *msg=malloc(sizeof(char)); and then i use gets(msg) to read it from user.At the end iam writting the message to the pipe with the write() function. In the server part now,i also allocate the buffer with malloc,but i dont know what the 3rd argument of the read() function should be...As i can undestand from the man page read's 3rd argument is the number of bytes you want to read and i assume that this is the strlen of the msg that the client is sending.The problem is that prior to read iam not able to know this.Is there a way to make this work or i should essentially use a MAX_SIZE for the buffer in server part. Thank you in advance for your time and your help.:)

Это было полезно?

Решение

The only possible solution is this mentioned from onon15 in the comment above."send the length of the buffer to expect, before sending the buffer".

Iam writting this as an answer to mark the question answered.

Thanks onon15!

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top