Johanna Jennekvist's profile

Network Server/Client

Network Programming Project


I created my own server and client for an online program where the main goal was to learn more about sockets and network connections without using built in Unity3D libraries. All code is written in C#. The basic functionality of the program is being able to add friends, chat with them and challenge them to a game of rock-paper-scissors, all over network. Three different database tables were also made to keep persistent data. The first one contains information about a user - login details, encrypted password and statistics regarding win/loss/draw in rock-paper-scissors. The second keeps track of which users are currently friends, and a third table contains information about pending friend requests if they are sent or responded to while one of the affected users were offline.  


Server
The server side was made in a standalone C# project. It is a multi-threaded server that accepts incoming client connections and keeps track of communication between client to server and client to client. The communication is handled through a serializable class NetworkMessage that serves as a protocol for messages sent between clients and server. A NetworkMessage is the base class defined a message sent over the network. It contains a header and a body. The server only reads the header which contains the recipient, and thereafter forwards the body of the message to that recipient. Many different types of messages can be sent over the network so I chose to derive different classes of NetworkMessage containing additional information that the message might need. For example when a user logs in, the server sends this user an update regarding his or her current friends, both pending and already existing, based on information gathered from the database. 

Client
The client side was made in Unity3D, with a very basic whitebox graphical interface, using only Unity default sprites. The basic functionality of the client includes logging in or creating a new account, adding friends by searching for their name - this searches the database for existing accounts and sends a friend request if they do exist. There's also a friends list showing tabs for online/offline/pending friends, as well as an inbox with unread/read messages tabs. If the user clicks a friend in their list, a profile is shown for that friend with the options of sending messages and checking their win/loss/draw ratio in rock-paper-scissors. There's also an option to challenge the friend to a game of rock-paper-scissors if he or she is currently online. If the game request is accepted, an ingame view is shown containing of three rounds where both players play live against the other. The program also handles pending game challenges, if a person has an awaiting challenge, he or she cannot challenge someone else before answering the current challenge. Receiving additional challenges whilst having a pending one will result in a little panel showing up that tells the user a challenge was missed. 

The most challenging part of this project was wrapping my head around socket programming as I had never done it before. Serializing messages to be sent over the network with minimalistic but informant data was probably the biggest obstacle. 



Network Server/Client
Published:

Network Server/Client

Published: