Keyboard firmwares for Atmel AVR and Cortex-M
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.

tcpecho_server_loop.py 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. """
  2. mbed SDK
  3. Copyright (c) 2011-2013 ARM Limited
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. """
  14. # Be sure that the tools directory is in the search path
  15. import sys
  16. from os.path import join, abspath, dirname
  17. ROOT = abspath(join(dirname(__file__), "..", ".."))
  18. sys.path.insert(0, ROOT)
  19. from workspace_tools.private_settings import LOCALHOST
  20. from SocketServer import BaseRequestHandler, TCPServer
  21. class TCP_EchoHandler(BaseRequestHandler):
  22. def handle(self):
  23. print "\nHandle connection from:", self.client_address
  24. while True:
  25. data = self.request.recv(1024)
  26. if not data: break
  27. self.request.sendall(data)
  28. self.request.close()
  29. print "socket closed"
  30. if __name__ == '__main__':
  31. server = TCPServer((LOCALHOST, 7), TCP_EchoHandler)
  32. print "listening for connections on:", (LOCALHOST, 7)
  33. server.serve_forever()