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:
38
server.py
Normal file
38
server.py
Normal 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
|
||||
Reference in New Issue
Block a user