Page 1 of 2 12 LastLast
Results 1 to 20 of 23

Thread: Allowing connections outside of LAN

  1. #1
    Join Date
    Dec 2012
    Posts
    27
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Allowing connections outside of LAN

    I've got a client which can connect to a server, and it works fine when the server is running in LAN, but if a client outside LAN tries to connect to the server, it doesn't allow it to connect. I have forwarded the port that the server uses to my ipv4 address but it still won't allow the connection.
    How can other clients connect to my server?

  2. #2
    Join Date
    Feb 2010
    Posts
    96
    Thanks
    4
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Allowing connections outside of LAN

    Have you forwarded the port through the firewall AND the router?

  3. #3
    Join Date
    Dec 2012
    Posts
    27
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Allowing connections outside of LAN

    I disabled my firewall and it still didn't work. Also, when I go to the firewall settings, there is no option to forward a port, only to allow another program.

  4. #4
    Join Date
    Feb 2010
    Posts
    96
    Thanks
    4
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Allowing connections outside of LAN

    AND router? Your port needs to be forwarded through your router also. Test here: http://www.yougetsignal.com/tools/open-ports/

    You shouldn't need to turn your firewall off. That shows a basic misunderstanding how the firewall works. You should read on how to open a port in your firewall.

  5. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Allowing connections outside of LAN

    Did you bind the port on the external interface or on all interfaces? Maybe it is just bound in the loopback device (thus allowing local connections)?

    Cheers,
    _

  6. #6
    Join Date
    Dec 2012
    Posts
    27
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Allowing connections outside of LAN

    Quote Originally Posted by prof.ebral View Post
    AND router? Your port needs to be forwarded through your router also. Test here: http://www.yougetsignal.com/tools/open-ports/

    You shouldn't need to turn your firewall off. That shows a basic misunderstanding how the firewall works. You should read on how to open a port in your firewall.
    Ok, I turned my firewall back on and opened the port that I need. I've also forwarded the port on my router but it still won't let anyone connect.

  7. #7
    Join Date
    Feb 2010
    Posts
    96
    Thanks
    4
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Allowing connections outside of LAN

    If the test tool I showed shows your port as open, then you have a problem in the code. Can you show us some of your code? Perhpas anda_soka's suggestion has relevence to your problem.

  8. #8
    Join Date
    Dec 2012
    Posts
    27
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Allowing connections outside of LAN

    Quote Originally Posted by prof.ebral View Post
    If the test tool I showed shows your port as open, then you have a problem in the code. Can you show us some of your code? Perhpas anda_soka's suggestion has relevence to your problem.
    The test tool said the port is closed when I entered my external IP address and my local IPv4 address.

    Here's the server code:

    main.cpp:
    Qt Code:
    1. #include <QtCore/QCoreApplication>
    2. #include "myserver.h"
    3.  
    4. int main(int argc, char *argv[]){
    5. QCoreApplication a(argc, argv);
    6. myserver server;
    7. server.startServer();
    8. return a.exec();
    9. }
    To copy to clipboard, switch view to plain text mode 

    myserver.h:
    Qt Code:
    1. #ifndef MYSERVER_H
    2. #define MYSERVER_H
    3.  
    4. #include <QtNetwork/QTcpServer>
    5. #include <QDebug>
    6. #include <iostream>
    7. #include "mythread.h"
    8.  
    9. class myserver : public QTcpServer
    10. {
    11. Q_OBJECT
    12. public:
    13. explicit myserver(QObject *parent = 0);
    14. void startServer();
    15.  
    16. protected:
    17. void incomingConnection(int socketDescriptor);
    18.  
    19. };
    20.  
    21. #endif // MYSERVER_H
    To copy to clipboard, switch view to plain text mode 

    myserver.cpp:
    Qt Code:
    1. #include "myserver.h"
    2.  
    3. myserver::myserver(QObject *parent) :
    4. QTcpServer(parent)
    5. {
    6. }
    7.  
    8. void myserver::startServer(){
    9. if(!this->listen(QHostAddress::Any,1234)){
    10. qDebug() << "Server failed to start";
    11. }
    12. else{
    13. qDebug() << "Server started";
    14. }
    15. }
    16.  
    17. void myserver::incomingConnection(int socketDescriptor){
    18. mythread *thread = new mythread(socketDescriptor, this);
    19. connect(thread,SIGNAL(finished()),thread,SLOT(deleteLater())); //deletes the thread after its finished being used
    20. thread->start();
    21. }
    To copy to clipboard, switch view to plain text mode 

    mythread.h:
    Qt Code:
    1. #ifndef MYTHREAD_H
    2. #define MYTHREAD_H
    3.  
    4. #include <QThread>
    5. #include <QtNetwork/QTcpSocket>
    6. #include <QDebug>
    7.  
    8. class mythread : public QThread
    9. {
    10. Q_OBJECT
    11. public:
    12. explicit mythread(int id, QObject *parent = 0);
    13. void run();
    14.  
    15. public slots:
    16. void disconnected();
    17. void readyRead();
    18.  
    19. signals:
    20. void error(QTcpSocket::SocketError socketError);
    21.  
    22. private:
    23. QTcpSocket *socket;
    24. int socketDescriptor;
    25.  
    26. };
    27.  
    28. #endif // MYTHREAD_H
    To copy to clipboard, switch view to plain text mode 

    mythread.cpp:
    Qt Code:
    1. #include "mythread.h"
    2.  
    3. mythread::mythread(int id, QObject *parent) :
    4. QThread(parent)
    5. {
    6. this->socketDescriptor = id;
    7. }
    8.  
    9. void mythread::run(){
    10. socket = new QTcpSocket();
    11. if(!socket->setSocketDescriptor(this->socketDescriptor)){
    12. emit error(socket->error());
    13. return;
    14. }
    15.  
    16. connect(socket,SIGNAL(disconnected()),this,SLOT(disconnected()),Qt::DirectConnection);
    17. connect(socket,SIGNAL(readyRead()),this,SLOT(readyRead()),Qt::DirectConnection);
    18.  
    19. qDebug() << "client" << socketDescriptor << "connected";
    20. exec(); //stop thread from closing
    21. }
    22.  
    23. void mythread::readyRead(){
    24. QByteArray data = socket->readAll();
    25. qDebug() << "client" << socketDescriptor << "sent" << data;
    26. if(data == "J"){
    27. socket->write("hello");
    28. }
    29. }
    30.  
    31. void mythread::disconnected(){
    32. qDebug() << "client" << socketDescriptor << "disconnected";
    33. socket->deleteLater();
    34. exit(0);
    35. }
    To copy to clipboard, switch view to plain text mode 

  9. #9
    Join Date
    Feb 2010
    Posts
    96
    Thanks
    4
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Allowing connections outside of LAN

    Quote Originally Posted by ben1996123 View Post
    The test tool said the port is closed when I entered my external IP address and my local IPv4 address.
    Then your port isn't forwarded properly. Use your external IP address. There is a link underneath that you can click to fill the entry with your current IP address. The issue is likely your router at this point. Some routers are funky when it comes to port forwarding. My DLink router oddly doesn't forward ports externally .. only internally. But it does have a virtual server option that allows me to forward the port externally.

    Whatever the case may be, make sure your port appears as open to an external tool like the one I gave you. There is no point in checking code until you can confirm the port is visibly open the outside.

  10. #10
    Join Date
    Dec 2012
    Posts
    27
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Allowing connections outside of LAN

    Quote Originally Posted by prof.ebral View Post
    Then your port isn't forwarded properly. Use your external IP address. There is a link underneath that you can click to fill the entry with your current IP address. The issue is likely your router at this point. Some routers are funky when it comes to port forwarding. My DLink router oddly doesn't forward ports externally .. only internally. But it does have a virtual server option that allows me to forward the port externally.

    Whatever the case may be, make sure your port appears as open to an external tool like the one I gave you. There is no point in checking code until you can confirm the port is visibly open the outside.
    Hmm... I've tried forwarding it to my internal and external IP addresses and it still says the port is closed. Just to test it, I tried the test tool with port 80 and it still said the port is closed...

  11. #11
    Join Date
    Feb 2010
    Posts
    96
    Thanks
    4
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Allowing connections outside of LAN

    Port 80 is in use by your browser. Look: http://traipsemeta.madmathlabs.info/ That is the meta server I run for the OpenRPG virtual game table software. This is my IP and port 64.21.252.156:9558 ... Port 9558 is open.

  12. #12
    Join Date
    Dec 2012
    Posts
    27
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Allowing connections outside of LAN

    Quote Originally Posted by prof.ebral View Post
    Port 80 is in use by your browser. Look: http://traipsemeta.madmathlabs.info/ That is the meta server I run for the OpenRPG virtual game table software. This is my IP and port 64.21.252.156:9558 ... Port 9558 is open.
    Ok, well I just tried port 25565 from minecraft in the test tool which I know is open and it works, but the test tool still says its closed... Maybe I'm just doing something completely wrong...

  13. #13
    Join Date
    Feb 2010
    Posts
    96
    Thanks
    4
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Allowing connections outside of LAN

    Is your minecraft server running? Some routers stop port forwarding unless a service is running on it.

  14. #14
    Join Date
    Dec 2012
    Posts
    27
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Allowing connections outside of LAN

    Quote Originally Posted by prof.ebral View Post
    Is your minecraft server running? Some routers stop port forwarding unless a service is running on it.
    It wasn't, but I just turned it on and tried again with my external IP, LAN IPv4 and hamachi IPv4 and it said the port is closed for all of them :/

  15. #15
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Allowing connections outside of LAN

    Run your server.
    At a command prompt run:
    • netstat --programs --numeric --listening --inet (Linux)
    • netstat -ban (Windows)


    Does your server program appear in the list as LISTENING against the local address and port (1234) you expect.
    Is the Local Address 0.0.0.0 or something else like 127.0.0.1?
    If something else, is it the address your router is forwarding external connection requests to?

  16. #16
    Join Date
    Feb 2010
    Posts
    96
    Thanks
    4
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Allowing connections outside of LAN

    Quote Originally Posted by ben1996123 View Post
    It wasn't, but I just turned it on and tried again with my external IP, LAN IPv4 and hamachi IPv4 and it said the port is closed for all of them :/
    Firstly, Hamachi is a service that connects computers through the Hamachi mediator software. You are not going to be able to test an open port with that tool if you are using the Hamachi service. See if you can find an open port here: http://www.planetminecraft.com/forum...rvers-f57.html -or- http://www.planetminecraft.com/forum...r-t191569.html (#1 posted a mere 2 hours ago)

    Now try one here: http://minecraft-server-list.com/ -- Here the ports are forwarded correctly through the PC's firewall and router.

    The fact you are using Hamachi signals to me you are not forwarding ports through your router correctly. Members of the OpenRPG community use Hamachi, or like services, when they have trouble forwarding ports through their router.

  17. #17
    Join Date
    Dec 2012
    Posts
    27
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Allowing connections outside of LAN

    Quote Originally Posted by ChrisW67 View Post
    Run your server.
    At a command prompt run:
    • netstat --programs --numeric --listening --inet (Linux)
    • netstat -ban (Windows)


    Does your server program appear in the list as LISTENING against the local address and port (1234) you expect.
    Is the Local Address 0.0.0.0 or something else like 127.0.0.1?
    If something else, is it the address your router is forwarding external connection requests to?
    The local address is 0.0.0.0:1234, the foreign address is 0.0.0.0:0 and the state is LISTENING.

  18. #18
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Allowing connections outside of LAN

    OK, it is listening for connections on any interface.

    From your server can your client connect to 127.0.0.1 on port 1234?
    No: The client or server code is faulty
    Yes: Carry on

    From a machine on your LAN other than the server can your client connect to server's LAN IP address?
    No: The problem is quite probably your server's own firewall. Windows firewall or anti-virus perhaps?
    Yes: Carry on

    Install Wireshark or a similar tool on your server machine. Start a capture. For a machine outside your network can your client connect to the server?
    Yes: Problem solved
    No: Carry on

    Did you see the attempt to connect to port 1234 in Wireshark?
    No: Problem is the firewall or port forwarding from your external connection.
    Yes: Problem may still be a firewall on the server itself if it restricts by source IP address.

  19. #19
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Allowing connections outside of LAN

    Quote Originally Posted by ChrisW67 View Post
    Did you see the attempt to connect to port 1234 in Wireshark?
    No: Problem is the firewall or port forwarding from your external connection.
    Yes: Problem may still be a firewall on the server itself if it restricts by source IP address.
    Or (hoverever unlikely) firewall on the client machine blocking outgoing connections to unknown ports.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  20. #20
    Join Date
    Dec 2012
    Posts
    27
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Allowing connections outside of LAN

    Quote Originally Posted by ChrisW67 View Post
    OK, it is listening for connections on any interface.

    From your server can your client connect to 127.0.0.1 on port 1234?
    No: The client or server code is faulty
    Yes: Carry on

    From a machine on your LAN other than the server can your client connect to server's LAN IP address?
    No: The problem is quite probably your server's own firewall. Windows firewall or anti-virus perhaps?
    Yes: Carry on

    Install Wireshark or a similar tool on your server machine. Start a capture. For a machine outside your network can your client connect to the server?
    Yes: Problem solved
    No: Carry on

    Did you see the attempt to connect to port 1234 in Wireshark?
    No: Problem is the firewall or port forwarding from your external connection.
    Yes: Problem may still be a firewall on the server itself if it restricts by source IP address.
    Thanks for that information, I just tried to connect to my server on another computer on my network (using telnet in command prompt because my client program doesn't work on windows xp yet) and that worked when I connected to 192.168.0.4. I've installed wireshark so I can test with another computer outside my network (well, as soon as someone comes on skype for me to test it with ). I just noticed that my antivirus program was blocking some TCP connections, so I allowed port 1234 through. Hopefully I can get it to work soon :/

Similar Threads

  1. Replies: 2
    Last Post: 30th March 2011, 20:20
  2. QActionGroup allowing unchecking ?
    By divide in forum Qt Programming
    Replies: 0
    Last Post: 29th June 2010, 14:16
  3. Layouts and allowing view to stretch with main window
    By steg90 in forum Qt Programming
    Replies: 1
    Last Post: 15th May 2007, 10:30
  4. Allowing external events to fire during a tight loop
    By hardgeus in forum Qt Programming
    Replies: 6
    Last Post: 28th December 2006, 15:24
  5. QTable - allowing it to only enter ints
    By therealjag in forum Qt Programming
    Replies: 2
    Last Post: 14th February 2006, 17:33

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.