Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import socket # Import socket module
- s = socket.socket() # Create a socket object
- host = input("Podaj adres ip: ") # Get local machine name
- port = 2138 # Reserve a port for your service.
- response = 'st'
- if(s.connect_ex((host, port))== 0):
- while(response != 'dn'):
- ## receive info on enemy move status
- response = s.recv(2)
- response = response.decode()
- if (response == 'ok'):
- print('Opponent has hit one of your units')
- elif (response == 'no'):
- print('Opponent has missed')
- #input answer
- answer = input()
- answer = answer.encode()
- s.sendall(answer)
- #receive info on answer success
- response = s.recv(2)
- response = response.decode()
- if(response == 'ok'):
- print('Hit')
- elif(response == 'no'):
- print('Miss')
- response = ''
- else:
- print("kek")
- s.close # Close the socket when done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement