Clone of official tools

Committer:
Anders Blomdell
Date:
Thu Feb 04 17:17:13 2021 +0100
Revision:
47:21ae3e5a7128
Parent:
13:ab47a20b66f0
Add a few normpath calls

Who changed what in which revision?

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