Results 1 to 8 of 8

Thread: I cannot connect with server

  1. #1
    Join Date
    Nov 2012
    Posts
    232
    Thanks
    118
    Thanked 18 Times in 10 Posts
    Platforms
    Windows Android

    Default I cannot connect with server

    I cannot connect with server.

    I create a server how this: http://www.youtube.com/watch?v=BSdKkZNEKlQ

    I run the program. I see:

    28.png
    Server started!

    I run "cmd.exe" and write:

    telnet
    then:

    open 0.0.0.0 1234
    I see:

    29.png

    MyFirstServer.pro
    Qt Code:
    1. #-------------------------------------------------
    2. #
    3. # Project created by QtCreator 2013-08-14T15:00:25
    4. #
    5. #-------------------------------------------------
    6.  
    7. QT += core
    8. QT += network
    9. QT -= gui
    10.  
    11. TARGET = MyFirstServer
    12. CONFIG += console
    13. CONFIG -= app_bundle
    14.  
    15. TEMPLATE = app
    16.  
    17.  
    18. SOURCES += main.cpp \
    19. myserver.cpp
    20.  
    21. HEADERS += \
    22. myserver.h
    To copy to clipboard, switch view to plain text mode 

    main.cpp
    Qt Code:
    1. #include <QCoreApplication>
    2. #include "myserver.h"
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QCoreApplication a(argc, argv);
    7.  
    8. MyServer mServer;
    9.  
    10. return a.exec();
    11. }
    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 <QObject>
    5. #include <QDebug>
    6. #include <QTcpServer>
    7. #include <QTcpSocket>
    8.  
    9. class MyServer : public QObject
    10. {
    11. Q_OBJECT
    12. public:
    13. explicit MyServer(QObject *parent = 0);
    14.  
    15. signals:
    16.  
    17. public slots:
    18. void newConnection();
    19.  
    20. private:
    21. QTcpServer *server;
    22. };
    23.  
    24. #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. QObject(parent)
    5. {
    6. server = new QTcpServer(this);
    7.  
    8. connect(server, SIGNAL(newConnection()), this, SLOT(newConnection()));
    9.  
    10. if (!server->listen(QHostAddress::Any, 1234)) {
    11. qDebug() << "Server could not start!";
    12. }
    13. else {
    14. qDebug() << "Server started!";
    15. qDebug() << "Address: " << server->serverAddress();
    16. qDebug() << "Port: " << server->serverPort();
    17. }
    18. }
    19.  
    20. void MyServer::newConnection() {
    21. QTcpSocket *socket = server->nextPendingConnection();
    22.  
    23. socket->write("hello client\r\n");
    24. socket->flush();
    25.  
    26. socket->waitForBytesWritten(3000);
    27.  
    28. socket->close();
    29. }
    To copy to clipboard, switch view to plain text mode 

    Thank you!

  2. #2
    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: I cannot connect with server

    Do you understand what "0.0.0.0" means?
    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.


  3. #3
    Join Date
    Aug 2013
    Location
    Dubai, UAE
    Posts
    2
    Qt products
    Qt3
    Platforms
    MacOS X

    Default Re: I cannot connect with server

    Hi all,
    If any one has any idea about the problem which is mentioned by 8Observer8. please help i have the same problem.

  4. #4
    Join Date
    Nov 2012
    Posts
    232
    Thanks
    118
    Thanked 18 Times in 10 Posts
    Platforms
    Windows Android

    Default Re: I cannot connect with server

    Quote Originally Posted by wysota View Post
    Do you understand what "0.0.0.0" means?
    Yes, it's ip address.

  5. #5
    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: I cannot connect with server

    Quote Originally Posted by 8Observer8 View Post
    Yes, it's ip address.
    What kind of ip address? Do you understand what it points to? You will never be able to connect to 0.0.0.0.
    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.


  6. #6
    Join Date
    Nov 2012
    Posts
    232
    Thanks
    118
    Thanked 18 Times in 10 Posts
    Platforms
    Windows Android

    Default Re: I cannot connect with server

    > What kind of ip address? Do you understand what it points to?

    I do not understand. It's new for me. How to know this ip address?

  7. #7
    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: I cannot connect with server

    You probably want to connect to 127.0.0.1, usually one of the addresses associated with the system's loopback device.

    Since you listen to "any address" this one should be one of them.

    0.0.0.0 is sometimes used to mean "any address" in the context of listening on a server socket or binding a receiving UDP socket. It is never used as an address for connecting to a server.

    Cheers,
    _

  8. The following user says thank you to anda_skoa for this useful post:

    8Observer8 (14th August 2013)

  9. #8
    Join Date
    Nov 2012
    Posts
    232
    Thanks
    118
    Thanked 18 Times in 10 Posts
    Platforms
    Windows Android

    Default Re: I cannot connect with server

    Quote Originally Posted by anda_skoa View Post
    You probably want to connect to 127.0.0.1, usually one of the addresses associated with the system's loopback device.

    Since you listen to "any address" this one should be one of them.

    0.0.0.0 is sometimes used to mean "any address" in the context of listening on a server socket or binding a receiving UDP socket. It is never used as an address for connecting to a server.

    Cheers,
    _
    Thank you very much!

    Author used it in the video. How did I not notice...

    30.png

Similar Threads

  1. Connect to a web server
    By sliverTwist in forum Newbie
    Replies: 7
    Last Post: 25th February 2013, 08:19
  2. Connect To Sql Server With QT
    By METEOR7 in forum Qt Programming
    Replies: 6
    Last Post: 13th December 2011, 12:39
  3. program cannot connect to X server
    By Wazman in forum Qt Programming
    Replies: 3
    Last Post: 1st September 2009, 19:28
  4. cannot connect to X server
    By jcr in forum Qt Programming
    Replies: 1
    Last Post: 18th April 2007, 14:22
  5. connect to sql server
    By raphaelf in forum Qt Programming
    Replies: 15
    Last Post: 27th February 2006, 18:06

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.