32 #include <ksocketfactory.h>
34 using namespace MailTransport;
36 namespace MailTransport {
41 SocketPrivate(
Socket *s );
51 void slotStateChanged( QAbstractSocket::SocketState state );
52 void slotModeChanged( QSslSocket::SslMode state );
53 void slotSocketRead();
62 SocketPrivate::SocketPrivate(
Socket *s ) : q( s )
66 void SocketPrivate::slotConnected()
71 kDebug() <<
"normal connect";
74 kDebug() <<
"encrypted connect";
75 socket->startClientEncryption();
79 void SocketPrivate::slotStateChanged( QAbstractSocket::SocketState state )
82 kDebug() <<
"State is now:" << ( int ) state;
84 if ( state == QAbstractSocket::UnconnectedState ) {
89 void SocketPrivate::slotModeChanged( QSslSocket::SslMode state )
92 kDebug() <<
"Mode is now:" << state;
94 if ( state == QSslSocket::SslClientMode ) {
99 void SocketPrivate::slotSocketRead()
114 kDebug() << socket->isEncrypted() << m_msg.trimmed();
117 emit q->data( m_msg );
126 socket->ignoreSslErrors();
133 :
QObject( parent ), d( new SocketPrivate( this ) )
149 kDebug() <<
"Connecting to:" << d->server <<
":" << d->port;
160 static_cast<QSslSocket *
>( KSocketFactory::connectToHost( d->protocol, d->server,
163 d->socket->setProtocol( QSsl::AnyProtocol );
165 connect( d->socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)),
166 SLOT(slotStateChanged(QAbstractSocket::SocketState)) );
167 connect( d->socket, SIGNAL(modeChanged(QSslSocket::SslMode)),
168 SLOT(slotModeChanged(QSslSocket::SslMode)) );
170 connect( d->socket, SIGNAL(readyRead()), SLOT(slotSocketRead()) );
188 kDebug() <<
"C :" << cs;
191 d->socket->write( cs.
data(), cs.
size() );
197 bool ok = d->socket && d->socket->state() == QAbstractSocket::ConnectedState;
204 d->socket->setProtocol( QSsl::TlsV1 );
205 d->socket->startClientEncryption();
228 #include "moc_socket.cpp"
virtual void write(const QString &text)
Write text to the socket.
void setProtocol(const QString &proto)
set the protocol to use
void setSecure(bool what)
this will be a secure connection
void setServer(const QString &server)
set the server to use
QString objectName() const
Socket(QObject *parent)
Contructor, it will not auto connect.
virtual void reconnect()
Existing connection will be closed and a new connection will be made.
Responsible for communicating with the server, it's designed to work with the ServerTest class...
void connected()
emitted when there is a connection (ready to send something).
void setPort(int port)
set the port to use.
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void startTLS()
If you want to start TLS encryption, call this.