Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MySocket::MySocket (QObject *parent)
- : QObject (parent)
- {
- Socket_ = new QTcpSocket (this);
- connect (Socket_,
- SIGNAL (readyRead ()),
- this,
- SLOT (readAnswer ()));
- connect (Socket_,
- SIGNAL (disconnected ()),
- this,
- SLOT (disconn ()));
- connect (Socket_,
- SIGNAL (connected ()),
- this,
- SLOT (conn ()));
- connect (Socket_,
- SIGNAL (bytesWritten (qint64)),
- this,
- SLOT (writeAnswer (qint64)));
- Socket_->connectToHost ("chat.freenode.net", 8001);
- if (!Socket_->waitForConnected (30000))
- {
- qDebug () << "Connection error:" << Socket_->error () << Socket_->errorString ();
- return;
- }
- }
- void MySocket::readAnswer ()
- {
- if (Socket_->canReadLine () ||
- (Socket_->waitForReadyRead(30000) &&
- Socket_->canReadLine ()))
- {
- qDebug () << Socket_->readLine ();
- }
- }
- void MySocket::writeAnswer (qint64 size)
- {
- qDebug () << "Bytes send: " << size;
- }
- void MySocket::disconn ()
- {
- qDebug () << "Disconnected";
- }
- void MySocket::conn ()
- {
- QString data;
- data = "USER Oleg\r\n";
- if (Socket_->isWritable ())
- {
- qint64 sz = Socket_->write (data.toAscii ());
- qDebug () << "First write: " << sz;
- }
- data = "NICK MasterPeace\r\n";
- if (Socket_->isWritable ())
- {
- qint64 sz = Socket_->write (data.toAscii ());
- qDebug () << "First write: " << sz;
- }
- data = "JOIN #leechcrafter\r\n";
- if (Socket_->isWritable ())
- {
- qint64 sz = Socket_->write (data.toAscii ());
- qDebug () << "First write: " << sz;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement