Android: QTcpSocket issue



  • Hi everyone,

    I'm facing an issue with QTcpSocket on Android.
    My app is really simple, it does nothing but creating a QTcpSocket, connect the stateChanged signal to a lambda function and then bind it to a port.

    @
    int main( int argc, char* argv[] )
    {
    QGuiApplication app( argc, argv)
    QTcpSocket socket;
    QObject::connect(
    & socket,
    & QTcpSocket::stateChanged,
    []( QAbstractSocket::SocketState state )
    {
    qDebug() << "State changed:" << state;
    }
    if( ! socket.bind(48484) )
    {
    qDebug() << "Could not bind to port 48484";
    }
    int ret = app.exec();
    return ret;
    }
    @

    I am using Qt 5.3 for iOS and OSX while it is Qt5.3.1 for Android.
    On iOS and OSX i get the notification that the socket is in BoundState while for Android i get BoundState but right after it i get ClosingState then UnconnectedSate

    If I run this "example":http://en.wikipedia.org/wiki/Berkeley_sockets of server/client it seems to work.

    Does anyone ever had this issue ?
    Thanks :)



  • Did you set the "Network-Access-Rights" to your application? I think that needs to be done in some XML-file?



  • Indeed I have those permissions :
    @ <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>@

    Whent the socket state is ClosingState or UnconnectedState the socket error is "Transport endpoint is not connected"


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.