summaryrefslogtreecommitdiffstats
path: root/test_tool/ping_server.py
diff options
context:
space:
mode:
authorcathook <b01902109@csie.ntu.edu.tw>2014-11-09 02:40:08 +0800
committercathook <b01902109@csie.ntu.edu.tw>2014-11-09 02:40:08 +0800
commitfd1fbcecb1ef75fe8016ab909ae4092ca705b2f1 (patch)
tree252f682763ec8356bc01ebf8c611dcaa0a07515f /test_tool/ping_server.py
parent3f84cb8b7c2aa24e739ae1a02c883e1e4cdb4004 (diff)
downloadvim-shrvim-fd1fbcecb1ef75fe8016ab909ae4092ca705b2f1.tar
vim-shrvim-fd1fbcecb1ef75fe8016ab909ae4092ca705b2f1.tar.gz
vim-shrvim-fd1fbcecb1ef75fe8016ab909ae4092ca705b2f1.tar.bz2
vim-shrvim-fd1fbcecb1ef75fe8016ab909ae4092ca705b2f1.tar.lz
vim-shrvim-fd1fbcecb1ef75fe8016ab909ae4092ca705b2f1.tar.xz
vim-shrvim-fd1fbcecb1ef75fe8016ab909ae4092ca705b2f1.tar.zst
vim-shrvim-fd1fbcecb1ef75fe8016ab909ae4092ca705b2f1.zip
big change
Diffstat (limited to 'test_tool/ping_server.py')
-rwxr-xr-xtest_tool/ping_server.py62
1 files changed, 62 insertions, 0 deletions
diff --git a/test_tool/ping_server.py b/test_tool/ping_server.py
new file mode 100755
index 0000000..5cdf41b
--- /dev/null
+++ b/test_tool/ping_server.py
@@ -0,0 +1,62 @@
+#! /usr/bin/env python3
+
+import log
+import sys
+import tcp_server
+import threading
+
+from json_package import JSONPackage
+
+class _TCPConnectionHandler(threading.Thread):
+ """A thread to handle a connection.
+
+ Attributes:
+ _sock: The connection socket.
+ _users_text_manager: An instance of UsersTextManager.
+ """
+ def __init__(self, sock, users_text_manager):
+ """Constructor.
+
+ Args:
+ sock: The connection socket.
+ users_text_manager: An instance of UsersTextManager.
+ """
+ super(_TCPConnectionHandler, self).__init__()
+ self._sock = sock
+ self._users_text_manager = users_text_manager
+
+ def run(self):
+ """Runs the thread."""
+ request = self._receive()
+ self._handle(request)
+ self._sock.close()
+
+
+ def _handle(self, request):
+ """Handles the request.
+
+ Args:
+ request: The request package.
+ """
+ log.info(str(request.content) + '\n')
+ request.send_to(self._sock)
+
+ def _receive(self):
+ """Receive a request.
+
+ Return:
+ The request package.
+ """
+ request = JSONPackage()
+ request.recv_from(self._sock)
+ return request
+
+
+tcp_server._TCPConnectionHandler = _TCPConnectionHandler
+
+def main():
+ server = tcp_server.TCPServer(int(sys.argv[1]), None)
+ server.start()
+
+if __name__ == '__main__':
+ main()