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