Home Page > > Details

Ghostwriter ICS 53 Programming Course,Help With C++ Programming,c/c++ ProgrammingGhostwriter Help With Processing|Help With Python Programming

ICS 53, Winter 2021
Assignment 5: Client/Server programming
You will write a networked client/server application which allows a client program to query a
server program to fetch stock market information. Your programs will allow a user to examine
stock prices for two major stocks namely Apple(AAPL) and Twitter(TWTR). The user will enter
commands into the client program which runs on one machine. For each command entered by
the user, the client program sends a message containing the query command. The server
program receives the query and responds with a message containing the requested
information. Below, we will describe the details of query commands and the format of the stock
data.
1. Running the Client/Server
The application is actually two different programs, the client program and the server program.
These two programs should both be running as two separate processes which are invoked by
the user in a shell. These two programs may be running on the same machine but they may be
running on two different machines. Since the client and server are communicating using TCP/IP,
you will need to select a port to use for communication. ICS Computer Support has advised us
that ports 30000 – 60000 are all available for your use, so you can use any one of those ports.
2. Stock Data Format
Your program will use historical stock prices of AAPL and TWTR as the stock prices used for buy
and sell transactions. In addition to downloading this assignment from Canvas, you will need to
download the following two files: AAPL.csv and TWTR.csv. These two files contain stock price
data for AAPL and TWTR, respectively. When your server program starts executing, historical
price data will need to be read from these two files before any transactions can be made by the
client.
Each file contains stock price information on each trading day between 7/2/2018 and
6/30/2020. Each file is in ”CSV” format, which stands for ”comma-separated value”. The
contents of the file are a table with a series of columns. The first line contains the titles of each
column and every line after the first contains the data on each column. The column data on
each line is separated by a comma. The data that we are interested in on each line is the date
(first column) and the closing price (fifth column). Your program will need to read the closing
price on each day and store it so that it can be used as the stock price for buy and sell
transactions. You will notice that the files do not include information for all days such as
weekends and holidays, so there are gaps in the data.
3. Commands Summary
Your program should accept the following commands related to historical price data:
• Prices: This command should display the stock prices of a stock on a given date. This
command takes 2 arguments, name of the stock and the date. If the date entered by the user
does not correspond to any entries in the appropriate stock data file, the server will respond
with the string “Unknown” and this string should be printed on the screen by the client.
• MaxProfit: This command should calculate the maximum possible profit for a single share of a
given stock. This profit should be considered over the entire time period described by the
historical data, between 7/2/2018 and 6/30/2020. In other words, if you buy your stock when
the stock price is minimum and sell it when the stock price is at its max, what will be the profit.
Note that the selling date must be later than the buying date. This command takes 1 argument,
name of the stock (AAPL or TWTR).
• quit: This command ends the program
4. Starting the Server
If we assume that the name of the server’s compiled executable is “server” then you would
start the server by typing the following at a linux prompt,
“./server AAPL.csv TWTR.csv 30000”
(The last argument is the port number that the server will listen to. The previous arguments
indicate the CSV files to be read by the server)
The server must first read the contents of the CSV files provided in the command line
arguments. When the reading is finished, it should start listening to the client requests on the
port mentioned as the last command line argument and should print “server started\n”. It
should wait to receive messages from a client.
5. Starting the Client
If we assume that the name of the client’s compiled executable is “client” then you would start
the client by typing the following at a linux prompt:
“./client server.ics.uci.edu 30000”
(The first argument is the domain name of the server and the second argument is the port
number the server is listening to.)
Remember server.ics.uci.edu is just an example of the domain name of the machine that server
is running on. If you run both client and server on the same machine, you can use “localhost”
instead to loop back the connection between client and server. When the client starts it should
print a “> ” prompt on the screen and wait for input from the user. (Note: “> “ is one > and one
space.)
6. Message Format
Each message sent between the client and the server must contain two pieces of information, a
string, and the length of the string. In messages sent from the client, the string will be the query
command entered by the user. In messages sent from the server, the string will be the
requested stock price (for the Prices command) or the profit value (for the MaxProfit
command). Each message must be shorter than 256 bytes long and must be formatted as
follows:
● Byte 0: Length of the string
● Bytes 1 – n: Characters of the string
7. User interface of the Client
Requests for stock information are made by the user entering the query commands at the
client’s prompt. When this information is entered at the client’s prompt, the client will send a
request message containing the query command to the server, and the client will await a
response from the server. The server will send a response message containing the
corresponding information.. The client will print the received information to the screen, print a
prompt on a new line, and wait for more input from the user. An example of a user interaction
with the client is shown below. It is derived from the first row of database examples.
> Prices AAPL 2018-07-02
187.18
> Prices TWTR 2019-05-08
38.58
> MaxProfit AAPL
Maximum Profit for AAPL: 224.34
> quit
←you are back to the linux prompt.
The client will continue in this loop until the user enters “quit” which will cause the client’s
process to exit. (Note: No need to print anything after quit was entered.)
8. User Interface of the Server
Once running, the server will only accept requests sent from one client over the network. When
the server receives a request from a client, the server will print the requested query command
in the message on the screen on a new line. An example of the printed output of the server
when communicating with the client is shown below.
server started
Prices AAPL 2018-07-02
Prices TWTR 2019-05-08
MaxProfit AAPL
The server will continue responding to requests and printing the associated information until its
process is killed externally, for instance by a ctrl-c typed at the keyboard.
9. Example execution (both client and server run on circinus-28 in this example)
Client
$ ./client circinus-28 30010
> Prices AAPL 2018-07-02
187.18
> Prices TWTR 2019-05-08
38.58
> Prices AMZN 2019-05-08
Invalid syntax
> Prices TWTR 20-05-2019
Invalid syntax
> Prices AAPL 2023-05-05
Unknown
> MaxProfit AAPL
Maximum Profit for AAPL: 224.34
> quit
$
Server
$ ./server AAPL.csv TWTR.csv 30010
server started
Prices AAPL 2018-07-02
Prices TWTR 2019-05-08
MaxProfit AAPL
^C
$
10. Implementation Details
● If the command entered into the client is invalid for any reason, just print “Invalid
syntax\n”.
● The commands and arguments should be case-sensitive.
● When the date is provided as an argument to a command, it should be provided in
”YYYY-MM-DD” format.
● When a stock name is provided as an argument, it should be provided as its ticker
symbol, AAPL, or TWTR.
● If the date value typed into the client is not present in the stock’s file which is known to
the server, just print “Unknown” and continue the program.
11. Submission Instructions
Your source code must be two C files (client.c and server.c). Be sure that your program must
compile on openlab.ics.uci.edu using gcc version 4.8.5. You can check your gcc version with the
“gcc -v” command. Make sure that you do not use C99 features. Make sure both files can
compile with “gcc filename.c” and do not require any flags or modifications. Submissions will
be done through Gradescope. The first line of your submitted file should be a comment which
includes the name and ID number of you and your partner (if you are working with a partner).

Contact Us - Email:99515681@qq.com    WeChat:codinghelp
© 2014 www.asgnhelp.com
Programming Assignment Help!