Ich hab ein Problem mit flush() von einem TCPsocket unter WinXP(32Bit) mit Visual Studio Express 2005.
Ich verwende QT4.4 mit OGRE zusammen, ich denke das OGRE den Fehler irgendwie auslößt, bin mir aber überhaupt nicht sicher.
(OGRE: eine 3d grafikengine --> http://www.ogre3d.org)
Ich lasse mal alle Daten die nicht interressiern weg.
e_Client.cpp (in meinem fall die "Startdatei"):
Code: Alles auswählen
#include "e_Scene.h"
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"
#endif
#include <stdio.h>
#ifdef __cplusplus
extern "C" {
#endif
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
#else
int main(int argc, char **argv)
#endif
{
// Create application object
Scene app;
//in der Klasse Scene liegt der Fehler
try {
app.go();
} catch( Exception& e ) {
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
#else
std::cerr << "An exception has occured: " << e.getFullDescription();
#endif
}
return 0;
}
#ifdef __cplusplus
}
#endif
Code: Alles auswählen
#ifndef E_SCENE_H
#define E_SCENE_H
#include "e_Anwendung.h"
#include "e_chara.h"
#include "stdio.h"
#include <QList>
#include "e_socket.h"
class Scene : public ExampleApplication
{
public:
Scene();
~Scene();
//Funktionen
...
//Variablen
QList<chara *> charlist;
SceneNode *node;
Client socket; // <-- der socket der das Problem, hat
protected:
...
};
#endif
Code: Alles auswählen
#include "e_Scene.h"
#include <QDebug>
//Funktionen
...
Scene::Scene()
{
//Login darstellen fehlt
qDebug() << "login";
socket.login("ADMIN","test");
}
Scene::~Scene()
{
}
...
Code: Alles auswählen
#ifndef E_SOCKET_H
#define E_SOCKET_H
#include <QTcpSocket>
#include <QObject>
class QTcpSocket;
class Client: public QObject
{
Q_OBJECT
public:
Client();
void send(quint16 hd,QString data="");
void send(quint16 hd,qint32 hd2,QString data="");
void send(quint16 hd,qint16 hd2,QString data="");
void send(quint16 hd,qint8 hd2,QString data="");
void send(quint16 hd,bool hd2,QString data="");
void send(quint16 hd,qint32 hd2,qint32 hd3,QString data="");
void login(QString user, QString password);
public slots:
void connectToHost();
void read();
void dc();
void displayError(QAbstractSocket::SocketError socketError);
void senderhalten();
private:
QTcpSocket *tcpSocket;
QString text;
QString id;
quint16 blockSize;
};
#endif
Code: Alles auswählen
#include <QtGui>
#include <QtNetwork>
#include <string>
#include "e_socket.h"
Client::Client()
{
tcpSocket = new QTcpSocket(0);
connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(read()));
connect(tcpSocket, SIGNAL(disconnected()), this, SLOT(dc()));
connect(tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(displayError(QAbstractSocket::SocketError)));
//connect(textLineEdit, SIGNAL(returnPressed ()),
// this, SLOT(sendtext()));
qDebug() << "-->gestartet";
blockSize = 0;
tcpSocket->abort();
tcpSocket->connectToHost("192.168.1.2",3333);
qDebug() << "-->connected";
}
...
void Client::login(QString user, QString password)
{
send(2,user.size(),user + password);
}
...
void Client::send(quint16 hd,qint32 hd2,QString data)
{
QByteArray block;
QDataStream out(&block, QIODevice::WriteOnly);
out.setVersion(QDataStream::Qt_4_4);
out << quint16(0);
//out << QString("test:");
out << quint16(hd);
out << qint32(hd2);
out << data;
out.device()->seek(0);
out << quint16((block.size() - sizeof(quint16)));
tcpSocket->write(block);
//tcpSocket->flush();
//lblStatus->setText(data);
qDebug() << "Senden von " << data;
}
void Client::send(quint16 hd,qint16 hd2,QString data)
{
QByteArray block;
QDataStream out(&block, QIODevice::WriteOnly);
out.setVersion(QDataStream::Qt_4_4);
out << quint16(0);
//out << QString("test:");
out << quint16(hd);
out << qint16(hd2);
out << data;
out.device()->seek(0);
out << quint16((block.size() - sizeof(quint16)));
tcpSocket->write(block);
//tcpSocket->flush();
//lblStatus->setText(data);
qDebug() << "Senden von " << data;
}
...
alle send(...) sehel im grunde gleich aus
Das größte Problem ist, dass ich keine Fehlermeldung bekomme zumindest ist es für mich keine:
Code: Alles auswählen
Der Thread 'Win32 Thread' (0x6e4) hat mit Code 0 (0x0) geendet.
Das Programm "[3164] Client.exe: Systemeigen" wurde mit Code 0 (0x0) beendet.
(Übrigens klappt der server sowie die funktionen aus der e_socket.h/cpp auf der selben plattform nur ohne OGRE und mit einem QTGUI einbahnfrei....)
Weiß einer woran das liegen könnte?
Ich wäre echt sehr dankbar für hilfe.
Viele dank
Kallitokaco