Skip to content
Browse files

Basic function to run a server as a separate process

  • Loading branch information...
1 parent 05fb337 commit 8aac02fed1e58e9187aa3e478629a872c9559dfa @Teifion committed
Showing with 34 additions and 0 deletions.
  1. +34 −0 ttt_server.py
View
34 ttt_server.py
@@ -0,0 +1,34 @@
+import time
+
+def new_server(conn):
+ flag = True
+ timeout = 0
+ while flag:
+ # Timout
+ timeout += 1
+ if timeout >= 50:
+ flag = False
+ continue
+
+ # Check there is data to read
+ if not conn.poll():
+ time.sleep(0.1)
+ continue
+
+ # Data is there, lets go wild!
+ timeout = 0
+ data = conn.recv()
+
+ cmd, kwargs = data
+
+ if cmd == "quit":
+ flag = False
+ continue
+
+ elif cmd == "keepalive":
+ continue
+
+ else:
+ print("No handler for: {}, {}".format(cmd, str(kwargs)))
+
+

0 comments on commit 8aac02f

Please sign in to comment.
Something went wrong with that request. Please try again.