Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
Dieses Repo ist archiviert. Du kannst Dateien sehen und es klonen, kannst aber nicht pushen oder Issues/Pull-Requests öffnen.

tcpecho_server.py 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. from SocketServer import BaseRequestHandler, TCPServer
  15. from time import time
  16. from private_settings import LOCALHOST
  17. MAX_INDEX = 126
  18. MEGA = float(1024 * 1024)
  19. class TCP_EchoHandler(BaseRequestHandler):
  20. def handle(self):
  21. print "\nconnection received"
  22. start = time()
  23. bytes = 0
  24. index = 0
  25. while True:
  26. data = self.request.recv(1024)
  27. if not data: break
  28. bytes += len(data)
  29. for n in map(ord, data):
  30. if n != index:
  31. print "data error %d != %d" % (n , index)
  32. index += 1
  33. if index > MAX_INDEX:
  34. index = 0
  35. self.request.sendall(data)
  36. t = time() - start
  37. b = float(bytes * 8) * 2
  38. print "Throughput: (%.2f)Mbits/s" % ((b/t)/MEGA)
  39. server = TCPServer((LOCALHOST, 7), TCP_EchoHandler)
  40. print "listening for connections"
  41. server.serve_forever()