Advertisement
Guest User

Untitled

a guest
Jun 20th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import socket
  4.  
  5. def main():
  6. host = '192.168.0.100'
  7. # This value needs to be between 1-65535
  8. port = 12345
  9. # Define an IPv4 Socket supporting TCP
  10. sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
  11. # Allows us to quickly rebind ports as needed.
  12. sock.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
  13. # Initialize the socket
  14. sock.bind((host,port))
  15. # Set socket to listening mode.
  16. sock.listen(1)
  17. # Accept a connection.
  18. conn,addr = sock.accept()
  19. """
  20. This block of code continues to run until you press ctrl+c
  21. """
  22. while True:
  23. # Announce the connection.
  24. print "Incoming connection from: %s" % str(addr)
  25. # Receive the message.
  26. data = conn.recv(1024)
  27. # If no message, just stop.
  28. if not data:
  29. break
  30. # If there is a message, print it.
  31. else:
  32. print "%s: %s" % (str(addr),str(data))
  33. # This line is what actually sends your input.
  34. # Game Menu Begins
  35. # Send Game Options
  36. conn.sendall("WELCOME TO THE GAME:\n")
  37. conn.sendall("Option 1) GO NORTH\n")
  38. conn.sendall("Option 2) GO SOUTH\n")
  39. data = conn.recv(1024)
  40. if("NORTH" in data):
  41. conn.sendall("You travel north.\n")
  42. elif("SOUTH" in data):
  43. conn.sendall("You travel south.\n")
  44. else:
  45. conn.sendall("Invalid option, try again.\n")
  46.  
  47. conn.close()
  48. sock.close()
  49.  
  50. if __name__ == "__main__":
  51. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement