Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import socket
- import pickle
- # Import the functions from the networking tools module
- from fl_networking_tools import get_binary, send_binary
- '''
- Responses
- RESPONSE CODES
- 1 - Question
- 2 - Answer correct
- 3 - Answer incorrect
- 10 - Join ???
- '''
- # A flag used to control the quiz loop.
- playing = True
- quiz_server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- quiz_server.connect(("127.0.0.1", 2065))
- team_name = input("Enter team name:")
- # Sending a command to the server.
- send_binary(quiz_server, ["JOIN", team_name])
- #send_binary(quiz_server, ["QUES", ""])
- while playing:
- # The get_binary function returns a list of messages - loop over them
- for response in get_binary(quiz_server):
- # response is the command/response tuple - response[0] is the code
- if response[0] == 1: # The question response
- # Display it to the user.
- print(response[1])
- #get users answer
- ans=input('What is the answer?: ')
- #send answer back to the server
- send_binary(quiz_server,["SANS",ans])
- elif response != 2:
- print(response[1])
- send_binary(quiz_server, ["QUES", ""])
- elif response[0] == 3:
- print(response[1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement