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
@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();
QByteArray block;
QDataStream out(&block,QIODevice::WriteOnly);
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.
@void chatScreen::connectToServer(QString itemName){
// char *data = new char();
char *data = new char();
uint i;
i=1024;
uint port;
port = 1235;
QString ip;
for (int k=0;k < contactList.count();k++){
if(contactList.at(k)->getName()== itemName){
ip = contactList.at(k)->getIpAddress();
break;
}
}QTcpSocket *client = new QTcpSocket(this); client->connectToHost((QHostAddress)ip,port,QIODevice::ReadWrite); client->waitForConnected(); if(client->state()== QAbstractSocket::ConnectedState){ client->waitForReadyRead(); client->readLine(data,i); qDebug()<<data; QString datain = 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.
-
Maybe something wrong at j2me part? Have you tried to look for packets via sniffer (like wireshark)?