A server for all the classmates in CS521 to mine for 521COIN!
To become more familiar with:
- The pthread library and parallelization using threads
- The producer/consumer paradigm
- Network programming with sockets
- Performance measurement
- Introduction to proto buff
When the client connects to the server, it will first request a task. Then the server will create the task and send it back to the client. Once the task is received, the client can work on "mining", find a solution, and send it back to the server. The server will verify whether the solution is correct and send this boolean value back to the client. If the verification is True, the client can mine again!
client --> requests task --> server
server --> gives task --> client
client works on it
client --> sends solution --> server
server verifies
server --> sends verification --> client
- Compile
make
- Run Server
./coin-server port
port can be any four-digit number greater than 1024.
Optional additional arguments:
[-s seed] [-a adjective_file] [-n animal_file] [-l log_file]
* -s Specify the seed number
* -a Specify the adjective file to be used
* -n Specify the animal file to be used
* -l Specify the log file to be used
- Run Client
./client localhost port username
port should be the same port used to run the server. username can be any sequence of 24 characters.
This picture shows our client requesting the task and starting to work on it. After that, the client will send the solution to the server.

This picture shows that the server received the request from the client. Then it sends the task to the client immediately. After the server gets the solution sent by the client, it will verify the solution and send the verification result back to the client.
Protocol buffers are Google’s language-neutral, platform-neutral, extensible mechanism for serializing structured data. The data is defined in coin-message.proto and compiled into C-code using protoc --c_out= proto compiler.
In server.c, you can see how the defined envelope in coin-message.proto is used.
The generated C type CoinMsg__Envelope has a union-like payload field (one‐of), so you can send or receive any of the message kinds through exactly one socket call.
When you call your helper recv_envelope(fd), it reads the length prefix , unpacks the bytes into a CoinMsg__Envelope struct, and checks body_case so you know which type of messges is sent and call corresponding handler to handle the messages.
In short, proto buff provides auto generated functions and structs based on proto file and you can focus implementation instead of network transferring.

