-
Notifications
You must be signed in to change notification settings - Fork 20
Exercise2EscapeRoomSockets
Assigned | 2/4/2019 |
Due | 2/6/2019 |
Points | 25 |
This is a very simple assignment. You are going to take your Escape Room from the first assignment and make a client-server version. You literally should not need to modify your original file at all.
You are going to create two files. The first, a escape_room_server.py
is a server that will use your existing escape room code to provide a server version. You will need to know how to use sockets and I recommend you get familiar with the documentation found here.
The following is pseudo-code.
from escape_room import EscapeRoom
server_socket.listen(1)
while True:
conn, addr = server_socket.accept()
# create an escape room
# while the escape room status is locked
# read the data from conn
output = room.command(data.decode()) # encode converts from bytes to string
# send the output.encode() to conn (encode converts from string to bytes)
conn.close()
Again, this is pseudo-code. It does not have all the pieces. You could also chose to use with
statements like those shown in the Python sample code if you know how to use them. But the entire server should be very, very short.
Note that the server imports from escape_room
. This means escape_room.py
needs to be in the same directory. You can do the sym-link trick as you saw in class, or copy from your git hub repo to a "deploy" directory.
The client is even simpler. It does not need to import from escape_room
at all. Instead, it's a UI that simply receives user input, sends it over the socket, and reads the response.
You may use the local host IP address for both client and server (127.0.0.1) and any port of your choosing.
Because we will be auto-testing your code, please make sure that your client and server can function with NO arguments. If you use command-line parameters for host/port, follow the format in the extra credit section, but also make sure that you support default parameters if no host/port is explicitly given.
There are two opportunities for extra credit in this lab.
-
(3 points). Take one optional parameter for the server that is an integer port value. Take one optional parameter for the client that is either a host and port separated by a colon (e.g., "192.168.1.1:8000") or a port (wherein the ip address defaults to localhost).
-
(7 points). Support multiple simultaneous connections using either select or threads.
You should have the following files in your GitHub repository.
<your_repository_root>/src/exercises/ex2/escape_room_server.py
<your_repository_root>/src/exercises/ex2/escape_room_client.py
To repeat, your server and client should support NO COMMAND LINE parameters (host and port chosen by default). Furthermore, for extra credit, the server should take one parameter for the selected port, and the client should take one parameter for the host and port (":" or "")
The grading breakdown is somewhat simplified.
- Correct server: 15
- Correct client: 10