summaryrefslogtreecommitdiff
path: root/test/dumb_tcp_server.py
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2018-07-02 23:49:47 +0100
committerw0rp <devw0rp@gmail.com>2018-07-02 23:49:47 +0100
commit01c68fedd63ccb9360134dba1cd2c722bc9f7006 (patch)
tree086ad02a035a20acc12cfe2a693cb8c9db901466 /test/dumb_tcp_server.py
parentb637b35ea89a5a756477b9e2545a2f36299ac5fa (diff)
downloadale-01c68fedd63ccb9360134dba1cd2c722bc9f7006.zip
#830 Implement a socket wrapper API for use with LSP connections
Diffstat (limited to 'test/dumb_tcp_server.py')
-rw-r--r--test/dumb_tcp_server.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/test/dumb_tcp_server.py b/test/dumb_tcp_server.py
new file mode 100644
index 00000000..c15db65e
--- /dev/null
+++ b/test/dumb_tcp_server.py
@@ -0,0 +1,40 @@
+"""
+This Python script creates a TCP server that does nothing but send its input
+back to the client that connects to it. Only one argument must be given, a port
+to bind to.
+"""
+import os
+import socket
+import sys
+
+
+def main():
+ if len(sys.argv) < 2 or not sys.argv[1].isdigit():
+ sys.exit('You must specify a port number')
+
+ sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
+ sock.bind(('127.0.0.1', int(sys.argv[1])))
+ sock.listen(0)
+
+ pid = os.fork()
+
+ if pid:
+ print(pid)
+ sys.exit()
+
+ while True:
+ connection = sock.accept()[0]
+ connection.settimeout(5)
+
+ while True:
+ try:
+ connection.send(connection.recv(1024))
+ except socket.timeout:
+ break
+
+ connection.close()
+
+
+if __name__ == "__main__":
+ main()