Docsity

Distributed Operations Systems Principles - Project 2 | COP 5615, Study Guides, Projects, Research of Computer Science

Toggle sidebar
bg1
Project 2 – COP 5615
Fall 2008
Due Nov. 17 and Dec. 8
Alin Dobra
October 27, 2008
The goal of this project is to create a small game simulator using RPC. This will familiarize you
with RPC, synchronization and simulators. The idea is to have a number of independent clients
that each control a ball by specifying a actions on it (hit the ball in a specified direction with a
given speed). All the balls are moving on a 100ft X 100ft region and they are bouncing on the walls
if they hit them (just like a reflection). Also, the balls can hit each other in which case the balls
after the hit will move in such a way that the moment of inertia is conserved. Mathematically, for
objects 1 and 2, if v1,x and v1,y are the xand yvelocity coordinates of object 1 ( v2,x and v2,y have
similar meaning for object 2) than the speeds after the collision must satisfy the equations:
v1,x +v2,x =v
0
1,x +v
0
2,x (1)
v1,y +v2,y =v
0
1,y +v
0
2,y (2)
(3)
where the speeds v0are the velocities after collision. To keep matters simple, you can pick any
velocities after collision that satisfy the above equations. In particular, you do not need to conserve
the energy as well. For the collision with a wall, you just have to change the sign of the velocity
component orthogonal on the wall. For example, if the left wall is hit, component xis orthogonal
and the new velocities are:
v
0
1,x =−v1,x (4)
v
0
1,y =v1,y (5)
(6)
The server is responsible for running the game simulator. Clients can ask for their view of the
world (the position of their ball and the balls within a 10 feet radius) and can specify a change in
the velocity of their bowl. The whole system has to be implemented using the SUN RPC (rpcgen.
Phase I of the project – Due date Nov 17
In phase I of the project you have to implement two programs: client and server. Both should
be implemented using the SUN RPC. You have to use the program rpcgen to generate the RPC
code for your client and server. You can find a nice tutorial on rpcgen at http://docs.freebsd.
org/44doc/psd/22.rpcgen/paper.pdf.
1
pf3

Partial preview of the text

Download Distributed Operations Systems Principles - Project 2 | COP 5615 and more Study Guides, Projects, Research Computer Science in PDF only on Docsity!

Project 2 – COP 5615

Fall 2008

Due Nov. 17 and Dec. 8

Alin Dobra

October 27, 2008

The goal of this project is to create a small game simulator using RPC. This will familiarize you with RPC, synchronization and simulators. The idea is to have a number of independent clients that each control a ball by specifying a actions on it (hit the ball in a specified direction with a given speed). All the balls are moving on a 100ft X 100ft region and they are bouncing on the walls if they hit them (just like a reflection). Also, the balls can hit each other in which case the balls after the hit will move in such a way that the moment of inertia is conserved. Mathematically, for objects 1 and 2, if v 1 ,x and v 1 ,y are the x and y velocity coordinates of object 1 ( v 2 ,x and v 2 ,y have similar meaning for object 2) than the speeds after the collision must satisfy the equations:

v 1 ,x + v 2 ,x = v′ 1 ,x + v′ 2 ,x (1) v 1 ,y + v 2 ,y = v 1 ′,y + v 2 ′,y (2) (3)

where the speeds v′^ are the velocities after collision. To keep matters simple, you can pick any velocities after collision that satisfy the above equations. In particular, you do not need to conserve the energy as well. For the collision with a wall, you just have to change the sign of the velocity component orthogonal on the wall. For example, if the left wall is hit, component x is orthogonal and the new velocities are:

v′ 1 ,x = −v 1 ,x (4) v′ 1 ,y = v 1 ,y (5) (6)

The server is responsible for running the game simulator. Clients can ask for their view of the world (the position of their ball and the balls within a 10 feet radius) and can specify a change in the velocity of their bowl. The whole system has to be implemented using the SUN RPC (rpcgen.

Phase I of the project – Due date Nov 17

In phase I of the project you have to implement two programs: client and server. Both should be implemented using the SUN RPC. You have to use the program rpcgen to generate the RPC code for your client and server. You can find a nice tutorial on rpcgen at http://docs.freebsd. org/44doc/psd/22.rpcgen/paper.pdf.

Requirements for client:

The client is responsible for generating actions for its ball and displaying the local view of the corresponding ball. Two threads need to be implemented. One to continuously display the local state every 1 second (has to ask the server what the state is). The second thread needs to read user input and , after checking for errors, to send the command to the server. The input from the user consists in two numbers read from standard input: ∆x and ∆y. These are the numbers in the interval [− 1. 0 , 1 .0] that specify the change in velocity for the ball the client is responsible for. Specific requirements are:

  • The client program must be invoked in the following manner:

client ip_address_server ballID

thus the client takes as argument the IP address of the server in the format xxx.xxx.xxx.xxx. The second argument is the ID of the ball controlled by this client.

  • The client initializes a connection with the server. Once the connection is established, a message is printed on the screen to specify so.
  • After the connection is established, the client starts the thread that displays the current view and the thread that reads input from the user. This is executed in an infinite loop. The information that is printed on the screen is of the form:

(ballID posX posY) ...

Please print a single line with all the information.

  • Code should be written to intercept Ctrl+C (intercept signal SIGQUIT) to nicely close the connection.
  • If a connection cannot be established, an error message should be printed on the screen.

Requirements for server

The server is responsible for running the entire simulation and it is the only one that has the entire global view. 10 times a second, it has to simulate moving the balls using the last known velocity. If two balls come within .2 ft, the server considers that they collided and applies the collision equations. Also if a ball hits one of the walls the wall collision equations are applied. The server maintains the position of all the balls and their velocities. The second duty of the server is to listen to the client requests to change the velocities of the balls. The server cannot make any assumptions when the requests will come. If a request comes for the first time for a ballID, a random position and random velocity is assigned. The velocities of the balls cannot be changed during the simulation step described above since the simulation becomes inconsistent (use a mutual exclusion region). The third duty of the simulator is to respond to requests from the clients to give them the their local view. Make sure the view is stable (cannot give the position while running the simulation). If a client asks for the view of ballID for the first time the random initialization described above