Guest User

Untitled

a guest
Feb 14th, 2020
67
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python3
  2.  
  3. import socket
  4. import json
  5.  
  6. s = socket.socket()
  7. host = '172.20.4.13'
  8. port = 4444
  9. s.connect((host, port)) #connect to server
  10.  
  11. while True:
  12. command = raw_input("Command: ") #read input, used raw_input instead of input due to python2/3 mismatches
  13.  
  14. if command == "help":
  15. print("pressure,altitude,pressure,sealevel")
  16. else:
  17. dic = {"Cmd": command}
  18. dicJson = json.dumps(dic)
  19. s.sendall(dicJson.encode()) #send dic with input command to server
  20.  
  21. data = client.recv(1024) #read server response
  22. dataDec = data.decode()
  23. dicResponse = json.loads(dataDec)
  24. response = dicResponse["Response"]
  25. print(response) #print server response
RAW Paste Data