Results 1 to 2 of 2

Thread: QTcpSocket Being used already. How to redirect traffic to another host using the sock

  1. #1
    Join Date
    Sep 2011
    Posts
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QTcpSocket Being used already. How to redirect traffic to another host using the sock

    Hello everyone, So I'm following this tutorial over how to make a Multi-Threaded QTcpServer I know it's beefy stuff and has to come with knowlegde on how to work with it... But I'm just finding my way in it by practicing some code making some logistics and etc, etc. So I was following this tuto up, until the part that I wanted to take it to the next level.

    So I got the code up and running the server sits and listens on ... localhost like so:



    And I have in the mythread.cpp I have this setup:



    Which you can see I want to connect to a new host and sorta "redirect" what it has been already read and send it over to the new host...

    but when I launch everything and I send data to my localhost it reads it (fine) when I send it (fail) it says well obviously you can see: "QAbstractSocket::connectToHost() called when already looking up or connecting/connected to "70.42.236.84" Meaning that...?? It has already been called? WHAT?

    I'm kinda off starting with the QTcp Classes in Qt and well i'm getting the grip now on it... And I just wanted to know what could I do in order to make a successfull redirection of the data received by socket->readAll(); into the new host... not just sits there in localhost and 'Echo' the data to myself... Because this is what I was following up.. to make a server that listens to Localhost and echoes all data to itself XD kinda like the old servers used to be at the beginning stuff like that..

    Well if someone helps me out I will be very grateful! =D And thanks in advance.

    *NOTE: IF YOU STILL CAN't SEE THE IMAGES QUITE WELL YOU CAN ALWAYS Right Click => Open Image in New Tab =D DONE!
    Last edited by elmasmalo1; 8th January 2013 at 18:38.

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: QTcpSocket Being used already. How to redirect traffic to another host using the

    I appears that you are connecting to a host, which you already connected earlier.

    What will happen if MyThread::readReady() is called twice? ...Yes, you will try connecting to host which is already connected (or trying to connect becasue of the first call to readReady()).

    I would suggest, connect to redirect host even before you accept incomming connections. This way you have an option to reject incommeing connections (or even stop listening if the redirect host is not available)
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

Similar Threads

  1. Redirect key strokes
    By iPick12 in forum Qt Programming
    Replies: 1
    Last Post: 11th September 2012, 16:55
  2. How to redirect to a URL in Qt
    By xyz in forum Newbie
    Replies: 8
    Last Post: 30th March 2012, 07:39
  3. Replies: 1
    Last Post: 17th July 2010, 12:02
  4. QT cannot read continuation or non-http traffic
    By SailingDreams in forum Qt Programming
    Replies: 9
    Last Post: 6th June 2009, 20:53

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.