Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Simple proxy, using two QTcpProxy

    General and Desktop
    3
    6
    3682
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • D
      DmT021 last edited by

      Sorry for my bad English.
      I need to make a simple proxy (without auth, etc). Every connection must be in separated thread. It must transer data from/to browser and remote server.
      My variant looks like this:
      I have made a class Server (: QTcpServer), with overloaded incomingConnection
      When incomingConnection emitted, I create new object of class Transfer, which create a new thread.
      In new thread I create an object of class TransferHandler, which create two sockets(named in and out) and connect signals readyRead from in to slot inReadyRead, from out to outReadyRead. When these signals emited, I just copy data from one into another (using readAll()).
      When signals disconnected() emitted, I just close sockects an delete objects.
      In method run() of thread object I call method exec().

      Problem --
      Answers for all requests are come. But in the browser there is only a part of answer(I think only first package was come). Then, the browser hangs in connected state, but did not gets data.

      Source code:

      http://dl.dropbox.com/u/3506908/transfer/Transfer.h
      http://dl.dropbox.com/u/3506908/transfer/Transfer.cpp

      PS:--
      If try to transfer data without events(did not call exec()), but just in cycle and using waitForReadyRead() all data transfers in to browser/server, but there is very long ping.--

      1 Reply Last reply Reply Quote 0
      • F
        florent.revelut last edited by

        I went quickly through your code, some comments:

        • it's not useful to spawn a thread each time, you might want to keep working in the main thread and using just signals / slots (will work nicely unless you have to scale drastically)
        • as your transferhandler class is waiting on your socket, you'd rather connect signals and slots as son as you've created the objects (otherwise, you might lose some events)
        • you mix synchronous (waitForxxx) and asynchronous, it's not easy to follow

        So far, without compiling it, I didn't see any trivial issue, I might have a further look later.

        1 Reply Last reply Reply Quote 0
        • D
          DmT021 last edited by

          Thanks, I'll rewrite code using only signals ans slots and paste sources here.

          1 Reply Last reply Reply Quote 0
          • D
            DmT021 last edited by

            Ok. I've rewrote proxy.
            http://dl.dropbox.com/u/3506908/transfer/SimpleProxy.zip
            This archive contains a project, with partially working proxy. It works fine with GET reqests, but doesn't work with POST.
            I get "400 bad request", when uploading file. And http://ping.eu/ping/ also doesn't work.
            What is wrong?

            1 Reply Last reply Reply Quote 0
            • D
              DmT021 last edited by

              Is anyone could answer me?

              1 Reply Last reply Reply Quote 0
              • U
                unmanner last edited by

                Hi All, and DmT021!

                I very-very interested in you QT proxy server! Could you please contact me here or by the mail: bushevuv@gmail.com

                If anyone knows someone about completed QT HTTP proxy server, please contack me :)

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post