Advertisement
johnpentyrch

client multithread1

Jun 18th, 2020
302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.25 KB | None | 0 0
  1. import socket
  2. import pickle
  3. # Import the functions from the networking tools module
  4. from fl_networking_tools import get_binary, send_binary
  5.  
  6. '''
  7. Responses
  8. RESPONSE CODES
  9. 1 - Question
  10. 2 - Answer correct
  11. 3 - Answer incorrect
  12. 10 - Join ???
  13. '''
  14.  
  15. # A flag used to control the quiz loop.
  16. playing = True
  17.  
  18. quiz_server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  19.  
  20. quiz_server.connect(("127.0.0.1", 2065))
  21. team_name = input("Enter team name:")
  22. # Sending a command to the server.
  23. send_binary(quiz_server, ["JOIN", team_name])
  24.  
  25.  
  26. #send_binary(quiz_server, ["QUES", ""])
  27.  
  28. while playing:
  29.     # The get_binary function returns a list of messages - loop over them
  30.     for response in get_binary(quiz_server):
  31.         # response is the command/response tuple - response[0] is the code
  32.         if response[0] == 1: # The question response
  33.             # Display it to the user.
  34.             print(response[1])
  35.             #get users answer
  36.             ans=input('What is the answer?: ')
  37.             #send answer back to the server
  38.             send_binary(quiz_server,["SANS",ans])
  39.         elif response != 2:
  40.             print(response[1])
  41.             send_binary(quiz_server, ["QUES", ""])
  42.         elif response[0] == 3:
  43.             print(response[1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement