2 Attachment(s)
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:
Attachment 9415
Server started!
I run "cmd.exe" and write:
then:
I see:
Attachment 9416
MyFirstServer.pro
Code:
#-------------------------------------------------
#
# Project created by QtCreator 2013-08-14T15:00:25
#
#-------------------------------------------------
QT += core
QT += network
QT -= gui
TARGET = MyFirstServer
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp \
myserver.cpp
HEADERS += \
myserver.h
main.cpp
Code:
#include <QCoreApplication>
#include "myserver.h"
int main(int argc, char *argv[])
{
MyServer mServer;
return a.exec();
}
myserver.h
Code:
#ifndef MYSERVER_H
#define MYSERVER_H
#include <QObject>
#include <QDebug>
#include <QTcpServer>
#include <QTcpSocket>
{
Q_OBJECT
public:
explicit MyServer
(QObject *parent
= 0);
signals:
public slots:
void newConnection();
private:
};
#endif // MYSERVER_H
myserver.cpp
Code:
#include "myserver.h"
MyServer
::MyServer(QObject *parent
) :{
connect(server, SIGNAL(newConnection()), this, SLOT(newConnection()));
qDebug() << "Server could not start!";
}
else {
qDebug() << "Server started!";
qDebug() << "Address: " << server->serverAddress();
qDebug() << "Port: " << server->serverPort();
}
}
void MyServer::newConnection() {
QTcpSocket *socket
= server
->nextPendingConnection
();
socket->write("hello client\r\n");
socket->flush();
socket->waitForBytesWritten(3000);
socket->close();
}
Thank you!
Re: I cannot connect with server
Do you understand what "0.0.0.0" means?
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.
Re: I cannot connect with server
Quote:
Originally Posted by
wysota
Do you understand what "0.0.0.0" means?
Yes, it's ip address.
Re: I cannot connect with server
Quote:
Originally Posted by
8Observer8
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.
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?
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,
_
1 Attachment(s)
Re: I cannot connect with server
Quote:
Originally Posted by
anda_skoa
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...
Attachment 9417