PDA

View Full Version : IP Routing QTcpSocket



naturalpsychic
30th March 2012, 18:29
I have very very simple network application based on QTcpSocket and QTcpServer. Client/Server in the same applicatino

Click here to browse (http://www.icplusplus.com/opensrc/browse.php?zf=43ea83881e3e75850cbbeba68ad6214e67a9 4c1c/bcdaf552fd5503fd4a1842a6605ff4dbdcda4bc1.zip&o=43ea83881e3e75850cbbeba68ad6214e67a94c1c)


Problem is that it works fine in localhost but I need to know the way (or at least be referred to correct reading) so that I can transmit data over the internet.

From my understanding (correct me if I am wrong):
this application sends data to correct receiver's IP. But only to router. router does not send to correct machine with port 1590 (for this example) so data floats around.


could I please get a better understading or could I please get help with how to implement it in a correct way in order to send it over WAN

wysota
30th March 2012, 18:42
Oh goody... another app with a network thread. And a broken one too since the received() slot runs in the main thread. Oh... a cross-thread direct signal-slot connection... That's certainly not the proper way to do it...

naturalpsychic
31st March 2012, 02:19
:)

thanks but sorry this answer s no closer to helpful

ChrisW67
31st March 2012, 06:44
Problem is that it works fine in localhost but I need to know the way (or at least be referred to correct reading) so that I can transmit data over the internet.

Nothing special is required. Just put the correct address on the attempt to connect.

From my understanding (correct me if I am wrong):
this application sends data to correct receiver's IP. But only to router. router does not send to correct machine with port 1590 (for this example) so data floats around.

Your application creates a connection to a given IP address (or fails) and then sends data. Your application has nothing to do with, and need not worry about, how your operating system and any intervening system makes that connection or delivers that data (e.g it could use IPoAC (http://en.wikipedia.org/wiki/IP_over_Avian_Carriers) and your app will not know or care) . In the case of TCP you don't even have to worry about data arriving out of order etc.

If you have external systems, e.g. firewalls, in the way then that is nothing to do with Qt or your application.


Wysota's comments come from frustration at the number of programmers that write simple Qt client server code with threads. Threads are almost certainly unnecessary and just add complexity and a range of other potential problems.

wysota
31st March 2012, 09:00
:)

thanks but sorry this answer s no closer to helpful

Ok, let's try to be more helpful. Remove the thread and it's likely your problems will vanish. If they don't, then have a look at your firewall settings.

naturalpsychic
31st March 2012, 18:07
Thanks to both of you. it clears a lot. I have respect for great people out there.

Is this a good idea to use QThreadPool [and QRunnable] instead???

if not even that then whats the best (and professional) way to manage multiple connections (clients) at the same time?

wysota
31st March 2012, 20:59
Is this a good idea to use QThreadPool [and QRunnable] instead???

if not even that then whats the best (and professional) way to manage multiple connections (clients) at the same time?

You can handle multiple connections in the same (main) thread. You don't need any extra threads.

naturalpsychic
1st April 2012, 03:22
You can handle multiple connections in the same (main) thread. You don't need any extra threads.

But what if server has to perform big task (and different for each client)??? isn't that going to block main thread?

wysota
1st April 2012, 06:47
Then the server can perform the task and not networking operations in the external thread. There is no point in spawning threads if you don't know if you are going to need them at all.