Server
A server is a computer program or device that provides functionality for other programs or devices, called clients in a Client-Server Architecture. Many Machine Learning processes are accessed via servers.
Python Example
Python server details can be found here.
To download the code below, click here.
# Import the needed server package code. from BaseHTTPServer import BaseHTTPRequestHandler # Set global variables for parameters from the server start command. server_address = None port_number = None start_parameter_n = None # Define a callback class and methods to handle HTTP requests. class RequestHandler: # Define the HTTP headers. def _set_headers(self): self.send_response(200) self.end_headers() # Define the OPTIONS method. def do_OPTIONS(self): # Import the system package. import sys # Set the response code. self.send_response(200) # Set the response headers. self.send_header("Access-Control-Allow-Origin", "*") self.send_header("Access-Control-Allow-Methods", "GET, POST, OPTIONS") self.send_header('Content-type', 'text/html') self.end_headers( ) # Write the file. self.wfile.write("") # Flush the standard output. sys.stdout.flush( ) # Define HTTP methods that will be supported, such as GET, POST, etc. def do_GET(self): # Import the system package. import sys # Import the package of functions that will process the HTTP request. import processing_functions # Reference the global start command parameters. global start_parameter_n # Execute the HTTP processing initial function. processing_functions.initial_function(self, start_parameter_n) # Flush the standard output. sys.stdout.flush( ) # Define a function to start the HTTP server. def start_server( ): # Import needed packages. import argparse import SocketServer import sys # Reference the global parameters. global server_address global port_number global start_parameter_n # Add start command arguments to a parser. parser = argparse.ArgumentParser( ) parser.add_argument("--server_address") parser.add_argument("--port_number") parser.add_argument("--start_parameter_n") # Retrieve argument values from the start command. args = parser.parse_args( ) server_address = args.server_address port_number = int(args.port_number) start_parameter_n = args.start_parameter_1 # Instantiate a server request handler. request_handler = RequestHandler # Instantiate a TCP server. server = SocketServer.TCPServer((server_address, port_number), request_handler) # Start a server that will remain active after processing a request. server.serve_forever( ) # Execute the start server function. start_server( )