Imported challenge checks and helper classes

Added .gitignore file
Added python server example as used in the "Basically Gambling" challenge
Imported automatic chellange checks and ansicolor helper class
This commit is contained in:
Jan Groß
2018-07-08 19:13:41 -04:00
parent 2c718972c7
commit f765a0b6f9
7 changed files with 190 additions and 0 deletions

38
server.py Normal file
View File

@@ -0,0 +1,38 @@
import threading
import SocketServer
class ThreadedTCPRequestHandler(SocketServer.BaseRequestHandler):
def handle(self):
data = self.request.recv(1024)
cur_thread = threading.current_thread()
print "Received: {}".format(data)
response = "{}".format(cur_thread.name)
self.request.sendall(response)
class ThreadedTCPServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
pass
if __name__ == "__main__":
HOST, PORT = "localhost", 6667
server = ThreadedTCPServer((HOST, PORT), ThreadedTCPRequestHandler)
ip, port = server.server_address
# Start a thread with the server -- that thread will then start one
# more thread for each request
server_thread = threading.Thread(target=server.serve_forever)
# Exit the server thread when the main thread terminates
server_thread.daemon = True
server_thread.start()
print "Server loop running in thread:", server_thread.name
#server.shutdown()
#server.server_close()
while ( True ):
try:
server.get_request()
except KeyboardInterrupt:
print "Server Stopping"
server.shutdown()
server.server_close()
break