def __init__(self, db, qlist): self._qlist = qlist self._db = db self._consumers = [ ConsumerThread(i, self._qlist[i]) for i in xrange(len(qlist)) ] self._lb = LoadBalancer(len(qlist))
from socket import * import socket import threading import time import sys import logging from lb import LoadBalancer reverseProxy = LoadBalancer() class ProcessTheClient(threading.Thread): def __init__(self, connection, address): self.connection = connection self.address = address threading.Thread.__init__(self) def run(self): rcv="" while True: try: data = self.connection.recv(8192) self.destination_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) if data: server = reverseProxy.get_server() print(f"forwarded to server {server}") self.destination_sock.connect(server) self.destination_sock.sendall(data) data_balasan = self.destination_sock.recv(8192) self.connection.sendall(data_balasan) logging.warning(data) logging.warning(data_balasan)
def __init__(self): self.load_balancer = LoadBalancer() self.current = 0