31 lines
913 B
Python
31 lines
913 B
Python
import socket
|
|
|
|
# Config
|
|
SERVER_IP = "127.0.0.1" # Change to master server's IP
|
|
PORT = 5901
|
|
MY_ID = "1" # Team Number
|
|
PREV_ID = "0" # Team Number of Team Sending Clue (should be previous team, but in case of abscences)
|
|
|
|
# 1. GET: Wait for input
|
|
print(f"Waiting for Team {PREV_ID}...")
|
|
while True:
|
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
s.connect((SERVER_IP, PORT))
|
|
s.send(f"GET {PREV_ID}".encode())
|
|
input = s.recv(1024).decode().strip()
|
|
s.close()
|
|
|
|
if input != "-1": # -1 Means Clue Is Not Yet Sent
|
|
print(f"Received input: {input}")
|
|
break
|
|
|
|
# 2. TRANSFORM: Do your logic to convert input to output clue, which should also be an integer Number
|
|
output = int(input) + 42
|
|
|
|
# 3. PUT: Send output
|
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
s.connect((SERVER_IP, PORT))
|
|
s.send(f"PUT {MY_ID} {output}".encode())
|
|
s.close()
|
|
print(f"Sent output: {output}")
|