Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import socket
- def main():
- host = '192.168.0.100'
- # This value needs to be between 1-65535
- port = 12345
- # Define an IPv4 Socket supporting TCP
- sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
- # Allows us to quickly rebind ports as needed.
- sock.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
- # Initialize the socket
- sock.bind((host,port))
- # Set socket to listening mode.
- sock.listen(1)
- # Accept a connection.
- conn,addr = sock.accept()
- """
- This block of code continues to run until you press ctrl+c
- """
- while True:
- # Announce the connection.
- print "Incoming connection from: %s" % str(addr)
- # Receive the message.
- data = conn.recv(1024)
- # If no message, just stop.
- if not data:
- break
- # If there is a message, print it.
- else:
- print "%s: %s" % (str(addr),str(data))
- # This line is what actually sends your input.
- # Game Menu Begins
- # Send Game Options
- conn.sendall("WELCOME TO THE GAME:\n")
- conn.sendall("Option 1) GO NORTH\n")
- conn.sendall("Option 2) GO SOUTH\n")
- data = conn.recv(1024)
- if("NORTH" in data):
- conn.sendall("You travel north.\n")
- elif("SOUTH" in data):
- conn.sendall("You travel south.\n")
- else:
- conn.sendall("Invalid option, try again.\n")
- conn.close()
- sock.close()
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement