Results 1 to 20 of 23

Thread: Allowing connections outside of LAN

Hybrid View

Previous Post Previous Post   Next Post Next Post
  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...

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.