Q) Will I get partial credit for the project even if I don't complete it?
A) Yes, as always. Describe in a README.txt file the parts that work so that the TA can test it.
Q) Does RPG use /dev/dice to generate random numbers?
A) No, per the worksheet specifications. The RPG no longer uses /dev/dice. It uses srand() and rand() functions as in Project 1. We are done with device drivers. No need to wrestle with device drivers and the virtual machine in this phase of the project. Everything can be done on thoth.
Q) Does RPG need to handle signals?
A) No, that requirement has already been tested on project 4 and will not be tested on project 5. In other words, no double dipping. :)
Q) Does RPG need to save / restore?
A) Ditto. No, that requirement has already been tested on project 4 and will not be tested on project 5. In other words, no double dipping. :)
Q) Where should I start?
A) Your network lab is a very good starting point for the server side. The only difference is that the lab only accepted one connection from the client. RPG needs to be able to accept multiple connections from multiple players. So, the accept() call needs to be in a loop (like we saw on the TCP diagram on the slides). Below is pseudocode for what needs to be done:
int main(){ socket(); bind(); listen(); while(...) { accept(); // new socket // use new socket to send() / recv() from client } return 0;}
If you do the above, and process all commands correctly, you have created a single-player RPG. Players can only login to the server one by one sequentially since you accept and process connections one by one. Start from here before adding threads and making it a multi-player RPG.
Q) So how do you make it a multi-player RPG?
A) In order to do that, you must make the program multi-threaded to accept multiple simultaneous connections. You must create a new thread each time you accept a connection and then pass the socket file descriptor as an argument. Make sure you don't pass a pointer to a stack location when you do this. Refer to the slides on how to avoid this.
Q) What about the client?
A) We didn't practice writing a client in the network lab. So you are more on your own. But we already learned what to do in the client side in the lecture. Below is pseudocode for what needs to be done:
int main(){ socket(); // connect to the address you called bind() on in the server side connect(); // use socket to send() / recv() from server return 0;}