PDA

View Full Version : QTcpSocket Being used already. How to redirect traffic to another host using the sock



elmasmalo1
8th January 2013, 18:00
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:

http://i49.tinypic.com/ftaio.png

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

http://i46.tinypic.com/10fakjo.png

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!

Santosh Reddy
10th January 2013, 08:34
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)