0
votes

This question is related to Socket programming in C and Sleeping a worker thread in a file server.

I am very new to socket as well as pthreads and having to handle quite a large project.

I would like to know if a scenario as below is possible and how? I have multiple clients to a server and each client sends multiple messages to the server.Each client is serviced by a task/worker thread. A client sends a message and upon receiving a reply sends the next message till it is done and closes the connection. The task thread process one request from the client, sends its reply and sleeps till it receives the next message from the same client,till the client closes connection and the thread exits.

Now, as I said multiple clients connect at the same time. Will the server process all messages from one client and then service the next or receive messages in an interleved manner as it arrives keeping connections of all 'live' clients open.

1
my questions may seem to be repeating but am not very clear so had to ask. Would love to receive a link to any online tutorial that takes care of such things - Lipika Deka
Both scenarios are possible. Get this book - unpbook.com - it's the best tutorial you will find. If you are too impatient, read Beej's guide at beej.us/guide/bgnet - Nikolai Fetissov

1 Answers

0
votes

Will the server process all messages from one client and then service the next or receive messages in an interleved manner as it arrives keeping connections of all 'live' clients open.

Server process can handle multiple clients at the same time or in an interleved manner, depending you CPU and programming architecture.

Threaded programming + multi-core or multi-CPU can handle those requests at the same time. ^_^