Qtcpsocket connection Problem while connecting with j2me midlet.
Hi,
i am using QTcpServer and QTcpSocket for listening and establishing connection. QTcpServer accept connection and open a socket and, J2me server accept connection from my Qt app. but after that when i tried to transfer data. any incoming data is not detected on both sides any body has an idea how i can do this. both Qt and j2me app are reading/writing in UTF8 format.
newConn() is connected to the QTcpserver::newConnection signal
Code:
@void chatScreen::newConn(){
char *data = new char();
qDebug()<<"New Connection";
// qDebug()<<"threads "<<threads.count()<<" Textbrowsers "<<textBrowsers.count()<<"Sockets "<<connections.count();
uint i;
i=1024;
// QString name;
QTcpSocket *client
=server.
nextPendingConnection();
QString a
=tr
("(iq,") + ownUserName
+ tr
(")");
// out<<a.toAscii();
client->write(a.toUtf8());
client->flush();
client->waitForReadyRead();
client->readLine(data,i);
qDebug()<<data;
}@
connectToServer() is using to connect to server.
Code:
@
void chatScreen
::connectToServer(QString itemName
){// char *data = new char();
char *data = new char();
uint i;
i=1024;
uint port;
port = 1235;
for (int k=0;k < contactList.count();k++){
if(contactList.at(k)->getName()== itemName){
ip = contactList.at(k)->getIpAddress();
break;
}
}
client->waitForConnected();
client->waitForReadyRead();
client->readLine(data,i);
qDebug()<<data;
if(datain.startsWith(tr("(iq,"))){
QString a
= tr
("(hs)(") + QString::number(ownUserId
) + tr
(")(" )+ ownUserName
+ tr
(")(") + ownPhoneNumber
+ tr
(")(") + ownAlias+ tr(")(") + ownIpAddress + tr(")");
client->write(a.toUtf8());
client->flush();
}@
the above code is working fine when used to communicate between two Qt apps.
--
Re: Qtcpsocket connection Problem while connecting with j2me midlet.
Code:
char *data = new char();
Wrong!
Code:
qDebug()<<"threads "<<threads.count()<<
This doesn't predict a bright future.
When connecting to a non Qt based server or a Qt server that doesn't use QDataStream, this does not work. A DataStream is a binary stream only readable by a program that can actually decode it.
But you don't use it.
Code:
QString a
=tr
("(iq,") + ownUserName
+ tr
(")");
Wrong, use QString::arg and similar functions.
Wrong! Undefined behaviour.
You can not cast a QString to a QHostAddress.