0

I am unable to get any further information regarding this error:

QAbstractSocket::UnknownSocketError

The QT QAbstractSocket::SocketError provides only a basic explaination that some error has occured

An unidentified error occurred.

enum value = -1

Calling QTcpSocket::errorString() provides this:

"Unknown error"

There is one question regarding this here on SO but provides no real solution to solving the issue (and what was suggested I have done)

I have absoltely no idea how to further progress with this error

p.s. I looked for some stacktrace/backtrace option, didn't find anything - if there is, please leave a comment

UPDATE

Code:

//Server

//...
if (tcpServer.listen(QHostAddress().AnyIPv4, 5000)) {
    qDebug() << "tcpserver started on port : 5000";
}
else{
    qDebug() << "tcpserver failed to start";
}
//...

//Client

//...
tcp_con = new QTcpSocket(new QObject());
tcp_con->connectToHost("127.0.0.1", 5000);

switch (tcp_con->error()) {
    //...
    case QAbstractSocket::UnknownSocketError:
    qDebug() << "tcp error UnknownSocketError closed : " << tcp_con->errorString();
    return;
    //...
}

Client debug output:

tcp error UnknownSocketError closed :  "Unknown error"

Any advice?

Community
  • 1
  • 1
CybeX
  • 2,060
  • 3
  • 48
  • 115
  • Please provide an [mcve](http://stackoverflow.com/help/mcve) or, at the very least, some relevant code. – G.M. Feb 04 '17 at 10:56
  • try telnet as client to connect to your tcp server – Redanium Feb 04 '17 at 22:03
  • @Redanium thanks, I shall try it. But if it succeeds, it still proves that something in the client in not functioning properly. There are examples of fortune client and server provided by Qt. I took the core parts of connectToHost, etc. non of the QNetworkConfigurations, etc. I implemented this and still does not work, but their provided example does. I have to investigate this further – CybeX Feb 04 '17 at 22:05
  • @KGCybeX I tried your code in a simple example and the output is similar to yours.If you look at the fortune examples which are two **asynchronous** and **synchronous**, you are implementing the **client** in a synchronous way without the use of `bool QAbstractSocket::waitForConnected(int msecs = 30000)` and `UnknownSocketError` you can get it even if the connection is successful.So either use `bool QAbstractSocket::waitForConnected(int msecs = 30000)` for synchronous or use `[signal] void QAbstractSocket::connected()` (signal/slot mechanism) for asynchronous. – Redanium Feb 05 '17 at 18:55
  • 1
    Possible duplicate of [QTcpSocket connecting results in UnknownSocketError with errorString "UnknownError"](http://stackoverflow.com/questions/42042579/qtcpsocket-connecting-results-in-unknownsocketerror-with-errorstring-unknownerr) – Redanium Feb 05 '17 at 19:08

0 Answers0