A small protocol, end to end
In this group project, we built a C client and server over TCP to query historical stock-price data. I worked on the socket layer, message framing, command parsing, CSV handling, and the logic for interval profit/loss queries.
The server loads two historical datasets, PFE and MRNA, and serves requests from one connected client at a time. The client provides a command prompt and prints each response.
Make the message boundary explicit
The assignment constrained messages to a compact frame. We used a one-byte length prefix followed by an ASCII payload, allowing both sides to describe the command and response without a text delimiter convention.
The protocol supports two commands:
PricesOnDate YYYY-MM-DD
MaxPossible profit|loss PFE|MRNA START-DATE END-DATE
The first returns closing prices for a date. The second examines an interval for a buy followed by a sell. The datasets cover trading dates between July 2019 and June 2021, and prices are formatted to two decimals.
Separate loading from serving
The server reads the CSV files at startup and keeps date/price pairs in memory. Requests then use those tables rather than reopening a file for each query. Command parsing and date lookup form a boundary between a network payload and the dataset operations.
What a later review revealed
Revisiting the design highlighted three areas I would verify carefully: preserving input buffers during date parsing, consuming the complete length-prefixed payload across socket reads, and ensuring profit and loss calculations respect transaction order.
A profit calculation can scan forward while tracking the lowest earlier price. A loss calculation needs the corresponding earlier-high/later-low relationship. The two operations look similar, but reversing the wrong comparison can make a loss routine calculate a profit instead. This is a good example of why a small, known dataset is valuable when checking an algorithm.
Example build
gcc server.c -o server
gcc client.c -o client
./server PFE.csv MRNA.csv 30000
./client localhost 30000
What I learned
This project connected several kinds of correctness: byte-level framing, string parsing, date interpretation, and an algorithm with an ordering constraint. A request can be syntactically valid and still produce the wrong answer if those assumptions disagree. It was a useful foundation for thinking about APIs beneath the framework layer.