Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Qtcpsocket connection Problem while connecting with j2me midlet.
Forum Updated to NodeBB v4.3 + New Features

Qtcpsocket connection Problem while connecting with j2me midlet.

Scheduled Pinned Locked Moved Mobile and Embedded
2 Posts 2 Posters 2.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hasnain
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DenisKormalev
      wrote on last edited by
      #2

      Maybe something wrong at j2me part? Have you tried to look for packets via sniffer (like wireshark)?

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved