Help in Qt Socket Programing in Windows 7?
hi
im unable to communication data in my application server and client, i am use windows 7,when i use windows XP is work well, can anyone help me please
my code like this
in application Server :
main:
Code:
#include <QtCore/QCoreApplication>
#include "server.h"
int main(int argc, char *argv[])
{
MyServer server;
return a.exec();
}
server.cpp
Code:
#include <QtCore>
#include <QtNetwork>
#include "server.h"
#include "MyServerHandlerMethod.h"
{
connect(this,SIGNAL(newConnection()),this,SLOT(MyServerHandler()));
}
void MyServer::MyServerHandler()
{
if(!socket) return;
new MyServerHandlerMethod(socket);
}
MyServerHandlerMethod.h
Code:
#ifndef MYSERVERHANDLERMETHOD_H
#define MYSERVERHANDLERMETHOD_H
#include <QtCore/QString>
#include <QtNetwork>
#include <iostream>
using namespace std;
class MyServerHandlerMethod
: public QObject{
Q_OBJECT
public:
{
connect(socket,SIGNAL(readyRead()),this,SLOT(HandlerConnection()));
this->socket = socket;
}
}
signals:
private:
void ConnectClose()
{
socket->close();
delete socket;
deleteLater();
}
private slots:
void HandlerConnection()
{
this->input = data; //QString input
cout<< qPrintable(this->input)<<endl;
InputHandler();
ConnectClose();
}
};
#endif // MYSERVERHANDLERMETHOD_H
in client:
main
Code:
#include <QtCore/QCoreApplication>
#include "client.h"
int main(int argc, char *argv[])
{
client tryClient;
tryClient.send();
return a.exec();
}
client.h
Code:
#ifndef CLIENT_H
#define CLIENT_H
#include <QtNetwork/QTcpSocket>
{
Q_OBJECT
public:
void send()
{
const int Timeout = 5 * 1000;
clientSocket->connectToHost("localhost",4711);
if (!clientSocket->waitForConnected(Timeout)) {
return;
}
clientSocket->write("ACK");
}
private:
signals:
private slots:
};
#endif // CLIENT_H
please help me :(
Re: Help in Qt Socket Programing in Windows 7?
Have you checked that the Windows 7 firewall is letting connections in?
Re: Help in Qt Socket Programing in Windows 7?
thank, it's work, i open the port in window 7 in the firewall menu, im add new rule in inbound menu, and its work, thanks for your repply