BIRLA INSTITUTE OF TECHNOLOGY & SCIENCE, PILANI
IS ZC462 : Network Programming
II Semester 2014-15
Assignment
Weightage: 15% Due Date of Submission
===============================================================
Important to Note:
1. Don’t use temporary files and system() function.
2. Only working programs will be evaluated. If there are compilation errors, it will not be evaluated.
3. Provide makefile for each problem.
4. For any clarifications please contact me
5. Each problem carries 4 marks. 1 mark bonus.
Plagiarism will be thoroughly penalized.
===============================================================
P1. Consider a chat server. It is a concurrent server providing concurrency through prethreading. Server takes thread pool size N on the command line. Threads wait on mutex and then call accept(). Client is a telnet application. Client can send the following messages. All messages start with a 4 letter command, followed by text and ended by \r\n. Text is interpreted as per the command.
• JOIN \r\n: This is the first message sent by the client providing its own name.
• LIST: This message will fetch all the connected online user names.
• UMSG \r\n \r\n: This is the message used for sending message to particular person named tname. If such a person is online then message will be delivered, otherwise server sends ERROR .
• BMSG \r\n: This message will deliver msg to all the online users.
• LEAV\r\n: This message will make the server remove the client entry in its data structures and close the connection.
All shared data must be protected. Implement prethreads_chatserver.c as per above requirements.
P2. Write C programs shmclient.c and shmserver.c that do the following.
• Server creates a shared memory of 1 MB. Shared memory is protected by a semaphore S. Clients write messages into shared memory. Server sums up a and b and put the result into total.
• Message is of the format:
struct message{
int type;
int pid; //client’s pid
int slno; //incremented for every message
int a; //any number
int b; //any number
int total;//total of a and b, processed by server
};
• A client writes a message m of type 1 into shared memory by acquiring sizeof(m) bytes from S. A client can write several messages into shared memory at one time. But as soon as a client completes writing, control is given to server to read a message from the shared memory.
• Server reads one message at a time, processes and writes the reply with type of client’s pid into the shared memory after acquiring necessary bytes from S. Once the server writes the reply, control is given to the client, who needs to read that reply. Such a client can’t write but only read from shared memory. After the client completes reading, either server (for reading) or any client (for writing) can get chance to access shared memory.
Use semaphores wherever necessary to control access to shared memory. Print client’s pid, slno, a and b, shmid, semaphore value for every message the client puts in. Print server’s pid (with label “server”), slno, a, b, sum of a and b, shmid, and semaphore value for every message it processes. When server is exited through ctrl-c, it prints pid wise count of messages it processed.
P3. In this problem you will implement a command line interpreter or shell. The shell takes in a command from user at its prompt and executes it and then prompts for more input from user.
• shell should execute a command using fork()and execve() calls. Once the command is completed it should print its pid and status.
• shell should support background jobs.
o Handles Ctrl-C and Ctrl-z as depicted in the diagram below.
o When a command is typed ending with ‘&’, it is run as background job. Assume that you can take only one command at a time for this problem.
o Each job is identified with a job id (JID), a positive integer
o Support the following built-in commands
jobs: lists all background jobs with JID and process id and status
bg : restarts a stopped job by sending it SIGCONT signal and runs it in the background
fg : brings a job to foreground or restarts a stopped job by sending it SIGCONT signal and runs it in the foreground
kill : terminates the job
Write a program called shell.c that implements the above requirements.
P4. Develop a TCP based client-server application for the following. Do not use temporary file to store results.
Server takes port number on command line. Server can handle multiple clients concurrently.
o Server should use process-per-client method for handling concurrent clients.
o Assume that the searchable files reside in the same directory where the server is.
Client takes server domain name and a port number. Client connects to the server.
Client asks the user to enter
o query string: string to search for
o in the preceding results: Y or N. Y means search will be performed in the results of the previous query. N means search will be performed on the file specified.
o file: If second argument is N, then filename has to be specified.
Client sends the query in the following format delimited by $(assuming that $ will not occur in the arguments:
o Querystring$Y/N$filename
Server searches the file using the grep command and returns the results back to the client.
o There can be errors on server side namely FILE_NOT_FOUND (if the file not found), RECORD_NOT_FOUND (if the query doesn’t match any line the file).
o grep command can be executed as grep
o In case, the search has to be done on the results of previous query, those results need to be sent to grep using pipe and dup calls.
o Do not use temporary file to store results.
Implement searchclient.c and searchserver.c as per the above requirements.
How to upload?
Make a directory for each problem like P1, P2 etc and copy your source files into these directories.
Tar all of them into idno.tar
• Upload the file at taxila.
Last Completed Projects
| topic title | academic level | Writer | delivered |
|---|
Are you looking for a similar paper or any other quality academic essay? Then look no further. Our research paper writing service is what you require. Our team of experienced writers is on standby to deliver to you an original paper as per your specified instructions with zero plagiarism guaranteed. This is the perfect way you can prepare your own unique academic paper and score the grades you deserve.
Use the order calculator below and get started! Contact our live support team for any assistance or inquiry.
[order_calculator]