Guest User

Untitled

a guest
Jun 17th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. ----- include -------
  2. class Serveur : public QServerSocket{
  3.     Q_OBJECT
  4. public:  
  5.     Serveur(const QHostAddress & adr, int port = 4444);
  6.     Serveur(int port = 4444);
  7.     ~Serveur();
  8.     void newConnection(int socket);
  9.     signals:
  10.         void nouvelle_connection();
  11. };
  12.  
  13. ----- source ---------
  14. Serveur::Serveur( const QHostAddress & adr, int port) : QServerSocket(adr,port,20){
  15.     if (!ok())
  16.         app()->erreur_fatale("impossible d'ouvrir le port : "+Texte(port));
  17. }
  18. Serveur::Serveur( int port) : QServerSocket(port,20){
  19.     if (!ok())
  20.         app()->erreur_fatale("impossible d'ouvrir le port : "+Texte(port));
  21. }
  22.  
  23. Serveur::~Serveur()
  24. {
  25. }
  26.  
  27. void Serveur::newConnection(int socket)
  28. {
  29.     ClientCom* s = new ClientCom( this );   //hérite de qsocket
  30.     connect( s, SIGNAL(readyRead()), s, SLOT(traiter()) );
  31.     s->setSocket( socket );
  32.     emit nouvelle_connection();
  33. }
Add Comment
Please, Sign In to add comment