[SOLVED]Problem when using second socket.
-
wrote on 25 Mar 2015, 08:13 last edited by
Yes I do wait for the socket to connect using
if (!socket->waitForConnected(connectionTimeout)) { return false; }
And its hard to post the code as it has turned out to be quite lengthy. Yet my smtp client is a barebones version of this . Any changes that I have made could not be responsible as the way I connect and send the data is the same, and as I said it works fine by itself. As for the http server it contains a worker class that deals with sockets (moves them into a separate thread, connects to the host etc) and a tcpServer that uses the worker class in order to deal with multiple connections.
-
wrote on 25 Mar 2015, 08:21 last edited by
Is
write()
called just after that?? -
wrote on 25 Mar 2015, 08:42 last edited by ealione
No after that I wait for the smtp server to respond using
waitForResponse();
after that I follow with all the procedure that has to take place in order to communicate with an smtp server, like sending the EHLO/HELO message
socket->write(text.toUtf8() + "\r\n"); if (! socket->waitForBytesWritten(sendMessageTimeout)) { throw SendMessageTimeoutException(); }
-
wrote on 25 Mar 2015, 08:46 last edited by
Seems that
socket
is not connected when you usewrite()
.
I suggest to handle theQAbstractSocket::stateChanged()
signal to understand when the state changes after connection -
wrote on 25 Mar 2015, 08:53 last edited by
I did and it seems that it never changes state. I do not even connect with smtp.google when I use this class form inside my http server, which is weird as it connects just fine otherwise.
-
wrote on 25 Mar 2015, 09:07 last edited by
Are you sure your
socket
is not changed is some part in the code?? -
wrote on 25 Mar 2015, 09:19 last edited by
Yup you are correct I should have looked more carefully at my implementation. I had a placed an ! symbol incorrectly. Now as you suggested I can see the states. This is what I get
Sending verification email. QAbstractSocket::HostLookupState QAbstractSocket::ConnectingState QAbstractSocket::ConnectedState Failed to connect to host!
The last comment comes from
smtp.connectToHost()
Seems that it returns false, but at least this is a step forward.
-
wrote on 25 Mar 2015, 09:26 last edited by
Are you sure you don't need to have a SSL socket?? I think at least
smtp.gmail.com
requires it -
wrote on 25 Mar 2015, 09:31 last edited by
Yup that was it. Realised it just before I read your comment.
I am marking this as solved, thanks for the help mcosta. -
wrote on 25 Mar 2015, 09:33 last edited by
You're welcome
12/12