Ejemplo n.º 1
0
    def __init__(self):
        host = '0.0.0.0'
        port = 9991
        print('Listening on ' + host + ':' + str(port))

        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        #    self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
        bound = False
        while not bound:
            try:
                self.sock.bind((host, port))
                bound = True
            except:
                print('Error binding to port ' + str(port))
                time.sleep(30)

        self.sock.listen(5)
        while (True):
            try:
                conn, addr = self.sock.accept()
                conn.settimeout(1)
                inq = Queue()
                outq = Queue()
                dus = DustUtpSocket(inq, outq)
                proxy = TcpProxy(conn, outq, inq)
                conn = None
                proxy.start()
                dus.start()
            except:
                return
Ejemplo n.º 2
0
Archivo: proxy.py Proyecto: blanu/Dust
  def __init__(self):
    host='0.0.0.0'
    port=9991
    print('Listening on '+host+':'+str(port))

    self.sock=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
#    self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
    bound=False
    while not bound:
      try:
        self.sock.bind((host, port))
        bound=True
      except:
        print('Error binding to port '+str(port))
        time.sleep(30)

    self.sock.listen(5)
    while(True):
      try:
        conn, addr = self.sock.accept()
        conn.settimeout(1)
        inq=Queue()
        outq=Queue()
        dus=DustUtpSocket(inq, outq)
        proxy=TcpProxy(conn, outq, inq)
        conn=None
        proxy.start()
        dus.start()
      except:
        return
        self.inq = inq

    def start(self):
        t = Thread(target=self.run)
        t.setDaemon(True)
        t.start()

    def run(self):
        while True:
            line = self.inq.get()
            sys.stderr.write(line.decode('ascii') + "\n")
            sys.stderr.flush()


if __name__ == '__main__':
    if sys.argv[1] == '-s':
        server = True
    else:
        server = False

    inq = Queue()
    outq = Queue()

    lr = LineReader(inq)
    lp = LinePrinter(outq)
    dus = DustUtpSocket(server, inq, outq)

    lr.start()
    lp.start()
    dus.start()
Ejemplo n.º 4
0
Archivo: demo.py Proyecto: blanu/Dust
  def __init__(self, inq):
    self.inq=inq

  def start(self):
    t=Thread(target=self.run)
    t.setDaemon(True)
    t.start()

  def run(self):
    while True:
      line=self.inq.get()
      sys.stderr.write(line.decode('ascii')+"\n")
      sys.stderr.flush()

if __name__=='__main__':
  if sys.argv[1]=='-s':
    server=True
  else:
    server=False

  inq=Queue()
  outq=Queue()

  lr=LineReader(inq)
  lp=LinePrinter(outq)
  dus=DustUtpSocket(server, inq, outq)

  lr.start()
  lp.start()
  dus.start()