Zizilk
31st July 2010, 17:27
Hi all)
Well, i'm writing QT based server and Php based client. And has some problem now.
I succesfully connected client to server, Sent data from server and recived it on the client, but i have really big trouble when i tried to read from socket on the server side.
I can get onlu "null" string
Server see that something there are in socket, can get it size(using QtcpSocket function bytesAvailable()), but i can't get that Data.
void Server::z_read()
{
printf(">> Reciving \n");
QTcpSocket* Clientsocket=(QTcpSocket*)sender();
int incoming=Clientsocket->bytesAvailable();
printf(">> in Socket %d bytes \n",incoming);
char* recieveddata;
printf(">> Reading \n");
QDataStream in(Clientsocket);
in>>recieveddata;
printf(">> Recieved ok \n>> Recieved: %s\n",recieveddata);
}
Firstly i tried to modefy standart examples of "Fortune client", but i removed all checks to find problem. In think i've made a mistake somewhere with Qdatastream.
But also i tried use QIOdevice::read() function. There aren't any warnings or errors while compilling. But server crushed with no errors, when it trying to read recieved data.
i think i made somewhere small mistake, but i can't find it for two days.
I use Qt Creator 2.0.0 with it standart compiller.
Qt 4.6
OS Win 7 Starter (Yes i'm programming on netbook))
Ps i started to use QT one week ago)
Pps English is foriegn language for me. I'm sorry for all mistackes i've made.
Well, i'm writing QT based server and Php based client. And has some problem now.
I succesfully connected client to server, Sent data from server and recived it on the client, but i have really big trouble when i tried to read from socket on the server side.
I can get onlu "null" string
Server see that something there are in socket, can get it size(using QtcpSocket function bytesAvailable()), but i can't get that Data.
void Server::z_read()
{
printf(">> Reciving \n");
QTcpSocket* Clientsocket=(QTcpSocket*)sender();
int incoming=Clientsocket->bytesAvailable();
printf(">> in Socket %d bytes \n",incoming);
char* recieveddata;
printf(">> Reading \n");
QDataStream in(Clientsocket);
in>>recieveddata;
printf(">> Recieved ok \n>> Recieved: %s\n",recieveddata);
}
Firstly i tried to modefy standart examples of "Fortune client", but i removed all checks to find problem. In think i've made a mistake somewhere with Qdatastream.
But also i tried use QIOdevice::read() function. There aren't any warnings or errors while compilling. But server crushed with no errors, when it trying to read recieved data.
i think i made somewhere small mistake, but i can't find it for two days.
I use Qt Creator 2.0.0 with it standart compiller.
Qt 4.6
OS Win 7 Starter (Yes i'm programming on netbook))
Ps i started to use QT one week ago)
Pps English is foriegn language for me. I'm sorry for all mistackes i've made.