During this module we learned about networking in regards to games. However, initially we focused solely on the networking side of things. The module had two courseworks that built upon each other. The first was to create a server and client that could communicate with each other. However, both should follow established networking protocols; WhoIs, HTTP/0.9, HTTP/1.0 and HTTP/1.1. This server and client would be tested using a rigid testing system, and therefore we were required to program to a tight specification.
The Client: –
When the client is run it is passed a string[] called args. This contains the information required to identify the desired protocol and the information should be sent to the server. Below is the code for establishing the link with the server, as well as the request that is to be sent to the server for a particular server request.
sw.WriteLine send the request to the server. The server then sends a response. This response is read and checked through the use of serverResponse.Contains(“OK”). The response is then split apart to get the information we wanted. This relates back to the idea of a standardized system and therefore allows use to know the structure of the response based on the protocol we are working with.
The Server: –
The server receives requests from a client and returns a response based on the protocol used to make the request. Initially I have to identify the request type: GET, POST or PUT. Each protocols request is structured differently, but follows a standard. Therefore I am able to detect these differences to decide which protocol the server has been sent. Below is the code for handling a HTTP/0.9 request that contains the key word “GET”.
The server contains a dictionary which can be accessed using a key. When a “GET” request is made, the “Name” the client is searching for is identified and this is used as the key to get the “Location”. This location is what the client wants returned, and is therefore formed into a valid return request that can be handled on the other side of the communication. However, if the dictionary does not contain the key, we form a response that informs the client of an invalid request.
This project had some advanced features one of which was creating a database of all the data the server is provided with, and provide a text output file for storing this data. This data should be loaded at runtime should the user starting the server request it. The process of writing to the file was established as follows:
<script src=”https://pastebin.com/embed_js/C5RCu9Dt”></script>
The server also logs everything, making debugging and reviewing requests really easy.
This project was great. Not only did I learn alot about strict coding practices and protocols, but also gained a great insight into networking. A lot of the in engine work I do now doesn’t use these networking examples exactly, but knowing these basic processes gave me a great foundation on which to build on. This coursework was very successful seeing me getting full marks for my implementation.