[SOLVED]Problem when using second socket.
-
I have created a multithreaded html server that can receive and send data, including images and other files. I wanted to add the ability to send messages so I created a different library that connects to a host (e.g. smtp.google.com) and acts as a simple smtp client
socket->connectToHost(host, port);
and after logging in it writes my message
socket->write(text.toUtf8() + "\r\n");
If I test this on its own it works as expected and all messages get send.
After invoking this from my server though I get an error.
The server listens for traffic using another socket. When a user connects and visits a link for example I try to use my smtp client to send an email only to get this error
QIODevice::write: device not open
-
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.
-
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(); }
-
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.