Results 1 to 2 of 2
help me please.
1-Client-Server Communication using Message Queues. Two processes, client and server, communicate via two message queues, “Up” and “Down”. The client reads a message from the standard input ...
- 05-19-2010 #1Just Joined!
- Join Date
- May 2010
- Posts
- 1
i need help
help me please.
1-Client-Server Communication using Message Queues. Two processes, client and server, communicate via two message queues, “Up” and “Down”. The client reads a message from the standard input and sends it to the server via the “Up” queue, then waits for the server’s answer on the “Down” queue. The server is specialised in converting characters from lower case to upper case and vice versa. Therefore, if the client sends the message “CHANGE case” via the “Up” message queue, the server will read the message, convert it, and send the message “change CASE” via the “Down” queue. When the client receives the message from the server, it prints it out. You may assume the maximum size of any message is 256 bytes. Multiple clients must be able to connect to the “Up” and “Down” queues. However, what happens if one client puts a message to convert on the system and another client is waiting for it’s response from the queue? There are different ways to handle this, but you should handle this using typed messages. Each client has a particular client number that corresponds to its process ID. Use this client number as the client identifier, and use typed messages on the queue so that each client can always be sure to receive the message that it is waiting on to be converted.
Work: Implement the client and server according the above scenario. Make sure you understand the problem. An example of how you could run two processes is as follows:
shell_prompt$ ./server &
shell_prompt$ ./client
Insert message to send to server: message
Msg processed: MESSAGE
Insert message to send to server: UPPER CASE
Msg processed: upper case
Write two C programs client.c and server.c that implement the behaviour explained above. You may want to use the following conversion function for the server code:
void conv(char *msg, int size){
int i;
for(i=0; i<size; i++)
if(islower(msg[i]))
msg[i] = toupper(msg[i]);
else if(isupper(msg[i]))
msg[i] = tolower(msg[i]);
}
Each client should terminate when the user types to that client in the “quit” string. However, the client should still send the “quit” string to the server. The server should terminate when it receives a “quit” string. The server should be the responsible for creating and deleting the message queue resources.
2. Threads. Make a program where the main() thread creates two threads, a server thread and a client thread. The client thread should keep asking the user to introduce integer numbers. These numbers are transmitted to the server thread that performs the sum of all the numbers it receives. The communication between the client and server threads should be performed through shared memory and semaphores. The program should use POSIX:SEM unnamed semaphores (sem init(), sem close(), etc) instead of POSIX:XSI semaphores (semget(), etc). The shared memory used by the program should not be POSIX:XSI shared memory (shmget(), etc) nor POSIX:MAP shared memory (shm open(), etc). The client thread should have no input nor output arguments. The server shall receive the pointer to the shared memory area, and the semaphore variables through input arguments to the corresponding thread - this is the only method permitted for the server to know these values. If the user introduces a zero, then the client and server threads should both terminate (the zero does not
count as a term of the sum). Upon termination, the server should return the number of terms of the sum, and the result of the sum through output arguments of the thread. The main() thread should wait for the termination of the other two threads. After detecting the termination of both threads, the main() thread should print the number of integers that were summed and the result of the sum (these values should come from the output arguments of the client; no other method is permitted for the main() to receive these values), and then should terminate the program.
- 05-19-2010 #2
This looks like a homework question. Homework questions are not allowed per the forum rules:
http://www.linuxforums.org/forum/lin...ums-rules.htmlDISTRO=Arch
Registered Linux User #388732


