Jump to content

Server/Client and fifo

- - - - -

  • Please log in to reply
5 replies to this topic

#1
Roxas

Roxas

    Newbie

  • Members
  • Pip
  • 3 posts
Hi everyone
I'm writing a small C project for university purposes.
it consists in a simple Server-Client application on Linux, in which the Server holds/manages a database, and the Clients ask it for files. Server and Clients are linux executables, and for the exchange of messages, only 2 well known FIFOs are used (any private/dedicated fifo), with record lock on both to ensure mutual exclusion between the processes.
Now I need to write a small library that contains functions that the Clients need to use in order to interact with the Server, for example "login", "send", "receive", and so on.
This library is a static one, composed by source code + include file.
My question is:
where should the Client open the FIFOs? Should be opened inside the function library, or in the client code before calling any of those functions? and how to manage the file descriptors used when using library functions (assuming that a file descriptor is not an input parameter of those function) ?

I hope it is clear, sorry for my bad english.
Thanks!

#2
¥ Brutus ¥

¥ Brutus ¥

    Newbie

  • Members
  • Pip
  • 7 posts
I didn't understand the way you are going to use the FIFOs, can you provide more details about this mutual exclusion?

#3
Roxas

Roxas

    Newbie

  • Members
  • Pip
  • 3 posts
yes,
I will use advisory record/file lock over the 2 fifo..using fcntl() syscall
example: a client process wants to write something to the server..he checks if the FIFO is "free" with that syscall, if so, it takes control of it (so to block other processes), and once done its work, it frees the FIFO.
btw I understood that I MUST open the FIFO inside the library, so the whole "communication channel" MUST be masked by the library and trasparent to Clients.
my question now is, how can I open a file inside a library? where should I store the file descriptor variable that every function would use?

#4
¥ Brutus ¥

¥ Brutus ¥

    Newbie

  • Members
  • Pip
  • 7 posts
If you're talking about a Client/Server architecture i suppose you will deploy the two sides of the application in different machines; if so you cannot access the FIFOs through their file descriptors directly from the client, cause FIFOs are stored in the server, in a different file system.
Rather i think you have to develop a communication protocol that let you manage the FIFOs remotely!
For example i would insert in the library a function "lock" that includes these steps:

- Connect to the Server with a socket;
- Send a message to the server (e.g., "lock FIFO 1");
- Receive a server response (OK, FAILED, ...);

Is this enough to clarify your doubts?

#5
Roxas

Roxas

    Newbie

  • Members
  • Pip
  • 3 posts
thanks for the help
btw, Clients and Server will run in the same machine, the Server in the background I think, and multiple Clients interacts with it at the same time (for example with different istances of the shell).
I know it doesn't make sense in real life, but since it's a educational proect it doesn't matter.
Maybe it's better to think of it as a Database/Readers approach? but the readers can write too (that's why there's the lock) and the database is managed by the thing that I call Server.
so the 2 FIFO are stored in the same machine, and the Client should not know about them, the Client should only know that there is a library composed by functions that he can use to talk to the Server.
So I guess that I should declare 2 static variables inside the library and use them to point to the 2 file descriptors for read and write operations. Then, every function of the library would use that 2 file descriptors.
Would that be reasonable or there are better ways to achieve that sort of communication?

#6
¥ Brutus ¥

¥ Brutus ¥

    Newbie

  • Members
  • Pip
  • 7 posts
In this case I think that you approach will be good! ;)




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users