CSE1205/2100 Introduction to Computer Science and Engineering Network Gaming (T3) Lab
Introduction
In this lab, we will borrow some code from the Computer Engineering Internet of Things / Networks course to develop a networked version of a tic- tac-toe (T3) game. In doing so, you will also become accustomed to a simple UDP network protocol and server-client network models.
You will also learn more about the concepts in this lab in CSE 3318 (Algorithms and Data Stuctures), CSE 3320 (Operating Systems), CSE 4352 (IoT/Networks), and CSE 4344 (Networks).
Network Quick Primer:
When data is sent on an Ethernet connection in many applications, the data is sent between IP address and port pairs (collectively called a socket addresses).
The IP addresses we will use in the lab use the IPv4 protocol. An IPv4 address is 4 octets (4 bytes) long. In the lab, all the addresses are numbered 192.168.1.x, where x is a number between 1 and 254. To configure your RPi to operate on the lab network, you should enable DHCP so it will automatically get a unique address on the lab network. This will allow you to send data to and receive data from other computers in the lab.
Often on a network, there is a server and a client. For instance, when you use a web browser to connect to a web site, the browser is a client and the web site is a server. A physical or virtual machine may provide many services to users. Port numbers are used to expose services to external users using well known port numbers for each service. For instance, SSH and SFTP connect to a server using port 22 and web servers often use port 80. So when a web browser tries to get access a web site, it contacts the IP address at port 80. When port 80 is accessed, traffic is routed to the web server to process the get and post requests from the web browser. When port 22 is accessed, an SSH server handles the traffic.
There are two primary IP protocols that are used to send data on these ports Transport Control Protocol (TCP) and User Defined Protocol (UDP). TCP is more complicated as it contains complexity to reliably send large files
consisting of many packets of data. UDP on the other hand is very simple, but it just sends packets of data just once so there is a chance for a packet of data to get lost. So the trade-off is complexity vs simplicity.
Network Use for our Game:
For our lab, we will use the UDP protocol and implement a client and server system for game play. The server will monitor port 4096 and the client will monitor port 4097 for inbound UDP traffic. The choice of 4096 and 4097 are arbitrary, but are required for this project so game applications can inter- operate.
In our lab, you can send a string using the provided sendData function:
bool sendData(const char ipv4Address[], int port, const char str[])
You can receive a string using the provided receiveData function:
void receiveData(char str[], int str_length)
The string value sent and received with these message will be one of the following 10 case-sensitive strings:
invite Invite a user to start a game A1, A2, A3, B1, B2, B3, C1, C2, or C3 Game moves
If two users want to play, one of the users starts their game application as a server, which waits to accept an invitation from a client to start a game. The other user starts their game application as a client and sends an invitation to the server to start a game. In both applications, users alternate turns and send their game moves to each other. In this implementation, the client sending the invitation will request the server make the first game move.
Application Requirements General:
You should write your lab solution in a file t3.c, that includes the udp.h header. When you compile the code, you will use the following command:
gcc -o t3 t3.c udp.c
Application Requirements Command Line:
The application is named t3. Invoking the application requires 2 additional options the IP address of the remote machine you want to reach and the operating role of the application. The role will indicate whether the application starts as a:
– Server and accepts invitations from a client
– A client and sends an invitation to a server
The command line syntax is:
./t3 REMOTE_IP ROLE
Recent Comments