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
Liked By
Write Answer
Proxy Webserver in Python
Join MindStick Community
You have need login or register for voting of answers or question.
Prakash nidhi Verma
13-Jul-2018Socket 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