External Exam Download Resources Web Applications Games Recycle Bin

client server

server.py

from flask import Flask
from flask import request

app = Flask(__name__)

@app.route("/reverse")
def reverse():
  word = request.args.get("word")
  return word[::-1] #reverse word

app.run()

client.py

import http.client
my_word = input("Word to reverse: ")
httpServ = http.client.HTTPConnection("127.0.0.1", 5000)
httpServ.connect()
httpServ.request("GET", "/reverse?word={reverse}".format(reverse=my_word))
response = httpServ.getresponse()
print("Reversed word: " + str(response.read().decode("utf-8")))
httpServ.close()