Debug Server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.6 KiB

  1. #!/bin/env python3
  2. import socket;
  3. import sys;
  4. def init_socket():
  5. # Creates a TCP/IP socket
  6. # socket type .AF_INET is the Internet address family for IPv4.
  7. # .SOCK_STREAM is the socket type for TCP.
  8. debug_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  9. # Bind the socket to the port 8000
  10. debug_server_address = ('localhost', 8000)
  11. debug_socket.bind(debug_server_address)
  12. # Listen for incoming connections
  13. debug_socket.listen(1)
  14. while True:
  15. # Wait for a connection
  16. print >>sys.stderr, 'Waiting for a Connection'
  17. connection, client_address = debug_socket.accept()
  18. def check_bridge_socket():
  19. evt = None
  20. return evt
  21. def handle_bridge_evt(evt):
  22. """
  23. TODO: Whatever bridge events to handle
  24. """
  25. def check_debug_socket():
  26. dbg_evt = None
  27. return dbg_evt
  28. def handle_debug_evt(dbg_evt):
  29. """ TODO: Do something with the events here."""
  30. def run_loop():
  31. """ """
  32. while True:
  33. # 1. Check the BridgeSocket
  34. evt = check_bridge_socket()
  35. if evt != None:
  36. handle_bridge_evt(evt)
  37. dbg_evt = check_debug_socket()
  38. if dbg_evt != None:
  39. handle_debug_evt(dbg_evt)
  40. def main():
  41. init_socket()
  42. """
  43. 1. TODO: Open Server port that the device connects to.
  44. 2. TODO: Open Server port that an admin connects to, i.e., to test sending packets to
  45. 3. TODO (Optional): We might be able to start a Scapy [REPL](https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop)
  46. and then add these functions. That way the person in debugging the phone can do live testing.
  47. """
  48. if __name__ == '__main__':
  49. main()