Send a flag from a HTTP Server to Client python

329 views Asked by At

I have a basic HTTP server-client written in Python wherein the server has different modules (campaigns) to run. I want the client to interact with the server only when a certain campaign is up. I was thinking I could maybe create a flag whose value would depend upon the campaign and send this flag to the client when it connects and then depending on the flag the client-server can interact. But how do I do that?

Example:

#Server
def run(server_class, handler_class):
   server_add = (host, port)
   httpd = server_class(server_add, handler_class)
   httpd.serve_forever()

def campaign():
   c = input("Choose Campaign: \r\n 1. Cam1 \r\n 2. Cam2 \r\n")
   if c == 1:
      flag = "Run Cam1" #Set flag
      #Send flag to client
      run()
      do_cam1() #Call the defined function for Campaign 1
   elif c == 2:
      flag = "Run Cam2"
      #Send flag to client
      run()
      do_cam2()
   else:
      print "Invalid Campaign"


#Client
def client():
   server = ''
   c = httplib.HTTPConnection(server)
   #Read the flag here
   if flag == "Run Cam1":
      #Do Something
   elseif flag == "Run Cam2":
      #Do Something
   else:
      #Throw Some Error
   c.close()
0

There are 0 answers