Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTcpSocket states on Windows and Linux
QtWS25 Last Chance

QTcpSocket states on Windows and Linux

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 4.2k Views
  • 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.
  • A Offline
    A Offline
    Algirdasss
    wrote on last edited by
    #1

    Hy,

    It seems that QTcpSocket behaves differently on different platforms. I don't understand something here or that's normal behavior ... I wrote this simple test class: (header file content is not pasted here)

    @#include "TcpSocketTester.h"

    TcpSocketTester::TcpSocketTester(QObject *parent) :
    QObject(parent)
    {
    connect(&_socket, SIGNAL(connected()), this, SLOT(socketConnected()));
    connect(&_socket, SIGNAL(error(QAbstractSocket::SocketError)),
    this, SLOT(socketError(QAbstractSocket::SocketError)));
    connect(&_socket, SIGNAL(disconnected()), this, SLOT(socketDisconnected()));
    connect(&_socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)),
    this, SLOT(socketStateChanged(QAbstractSocket::SocketState)));

    _socket.connectToHost(QHostAddress("192.168.1.96"), 22154);
    

    }

    void TcpSocketTester::socketConnected()
    {
    qDebug() << QDateTime::currentDateTime().toString("hh:mm:ss.zzz") << ": CONNECTED";
    }

    void TcpSocketTester::socketError(QAbstractSocket::SocketError error)
    {
    qDebug() << QDateTime::currentDateTime().toString("hh:mm:ss.zzz") << ": SOCKET ERROR " << error;
    }

    void TcpSocketTester::socketDisconnected()
    {
    qDebug() << QDateTime::currentDateTime().toString("hh:mm:ss.zzz") << ": DISCONNECTED";
    }

    void TcpSocketTester::socketStateChanged(QAbstractSocket::SocketState state)
    {
    qDebug() << QDateTime::currentDateTime().toString("hh:mm:ss.zzz") << ": STATE " << state;
    }@

    IP address "192.168.1.96" that I try to connect to is not alive!!!

    This is output that I get under Ubuntu 10.04:

    "08:57:28.663" : STATE QAbstractSocket::HostLookupState
    "08:57:28.663" : STATE QAbstractSocket::ConnectingState
    "08:57:28.664" : STATE QAbstractSocket::ConnectedState
    "08:57:28.664" : CONNECTED
    "08:57:49.578" : SOCKET ERROR QAbstractSocket::RemoteHostClosedError
    "08:57:49.578" : STATE QAbstractSocket::ClosingState
    "08:57:49.578" : STATE QAbstractSocket::UnconnectedState
    "08:57:49.578" : DISCONNECTED

    This is output that I get under Windows XP:

    "09:13:17.546" : STATE QAbstractSocket::HostLookupState
    "09:13:17.546" : STATE QAbstractSocket::ConnectingState
    "09:13:59.546" : STATE QAbstractSocket::UnconnectedState
    "09:13:59.546" : SOCKET ERROR QAbstractSocket::NetworkError

    So it seems that under Linux socket signals that it is connected even if IP address is unreachable. Under Windows it seems to work as expected. But I had some cases under windows when it behaved the same way as in Linux, just didn't caught what was the reason.

    Maybe someone knows what is happening with these sockets??

    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