You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test.cpp 675B

12345678910111213141516171819202122232425262728293031
  1. #include "test.h"
  2. Test::Test(QObject *parent) : QObject(parent)
  3. {
  4. m_serv = new PTServer(this);
  5. connect(m_serv, SIGNAL(newConnection()), this, SLOT(m_newConnection()));
  6. connect(m_serv, SIGNAL(newClient(PTSocket*)), this, SLOT(m_newClient(PTSocket*)));
  7. }
  8. void Test::testListen(quint16 p)
  9. {
  10. Q_ASSERT(m_serv->listen(QHostAddress::Any, p));
  11. }
  12. void Test::testNewConnection()
  13. {
  14. ASSERT_LISTEN;
  15. PTSocket* sock = new PTSocket(this);
  16. m_clients.append(sock);
  17. sock->connectToHost("127.0.0.1", m_serv->serverPort());
  18. }
  19. void Test::m_newConnection()
  20. {
  21. qDebug()<<"New socket";
  22. }
  23. void Test::m_newClient(PTSocket* s)
  24. {
  25. qDebug()<<"New client:"<<s->peerAddress()<<s->peerPort();
  26. }