Socket programming in python is very user friendly user. user focusing on the application layer more than the network layer in python.
Creating an incoming socket :
*create a socket serverSocket in the __init__ method of the Server Class.
def __init__(self, config): # Shutdown on Ctrl+C
signal.signal(signal.SIGINT, self.shutdown)
# Create a TCP socket
self.serverSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Re-use the socket
self.serverSocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
# bind the socket to a public host, and a port
self.serverSocket.bind((config['HOST_NAME'], config['BIND_PORT']))
self.serverSocket.listen(10) # become a server socket
self.__clients = {}
Accept client and process:
while True:
# Establish the connection (clientSocket, client_address) = self.serverSocket.accept()
d = threading.Thread(name=self._getClientName(client_address),
target = self.proxy_thread, args=(clientSocket, client_address))
d.setDaemon(True)
d.start()
Redirecting the traffic:
# get the request from browser request = conn.recv(config['MAX_REQUEST_LEN'])
# parse the first line
first_line = request.split('\n')[0]
# get url
url = first_line.split(' ')[1]
How to test the server?
- Blacklisting Domains
- Content monitoring
- Logging
- HTTP WebServer + ProxyServer
Join MindStick Community
You need to log in or register to vote on answers or questions.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
Socket programming in python is very user friendly user. user focusing on the application layer more than the network layer in python.
Creating an incoming socket :
*create a socket serverSocket in the __init__ method of the Server Class.
Accept client and process:
while True:
Redirecting the traffic:
How to test the server?
- Blacklisting Domains
- Content monitoring
- Logging
- HTTP WebServer + ProxyServer