0

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()
Nomi
  • 11
  • 2
  • 1
    I think it would be better if you include the code in the question rather than its screenshot – DPM Sep 07 '17 at 13:32
  • 1
    Code should be pasted as a text not an image. – mrogal.ski Sep 07 '17 at 13:35
  • @DPM I was earlier having problem posting it as text since I'm new here and I thought it didn't matter whether I post the code as text or image. Anyway thanks for letting me know, I've replaced the image with text. It'd be really great if you could help me with the question. – Nomi Sep 08 '17 at 04:03
  • It looks like that is something you could implement but you just think your solution is not particularly elegant, right? That'd be kind of a broad question for this site. If I were you I would implement a working solution and validate it over at code review. Take a look here https://codereview.meta.stackexchange.com/questions/2436/how-to-get-the-best-value-out-of-code-review-asking-questions – DPM Sep 08 '17 at 11:33
  • @DPM great thanks, I'll take a look at it. – Nomi Sep 08 '17 at 11:54

0 Answers0