void ServeurLabyrinthe::Start()
{
	std::string message;
	while (true)
	{
		while(est_invalide(m_socketClient))
		{
			accepter_client();
		}

		message = tolowercase(recevoir());

		switch (message[0])
		{
			case DROITE: 
            m_Carte.tryMoveRight();
				break;
			case GAUCHE:
            m_Carte.tryMoveLeft();
				break;
			case HAUT:
            m_Carte.tryMoveUp();
            break;
         case BAS:
            m_Carte.tryMoveDown();
				break;
			default:
				break;
		}

      if (m_Carte.is_PartieFinie())
      {
         envoyer("*");
      }
      else
      {
         // Envoyer nouveau vecteur.
         std::vector<std::vector<char>> vector = m_Carte.getVec();

         for (int y = 0; y < m_Carte.height(); ++y)
         {
            std::string s(vector[y].begin(), vector[y].end());

            envoyer(s);
         }

         envoyer("@");
      }
	}
}
Exemple #2
0
void log_windows()
{
	/*Recuperation de la boite aux lettres*/
	int bal_log_windows = mq_open( BALWIN, O_RDONLY );
	log_t message;	
	
	do/*Envoi de message tant qu'on ne reçoit pas de trame de fin*/
	{
		/*Reception du message du superviseur*/
		mq_receive(bal_log_windows, message, sizeof(log_t), NULL);
		if( strcmp(message, TRAME_FIN) ) /*Si ce n'est pas un message de fin...*/
			envoyer(message);
	}
	while( strcmp(message, TRAME_FIN) );
	printf("Fin log win\n");
	
	pthread_exit(0);
}
Exemple #3
0
int main(int argc, char ** argv) {

  int PORT;
  if(argc>1) {
    PORT = atoi(argv[1]);
  } else {
    PORT = 5555;
  }

  int sock = init_socket();
  if(sock == -1) {
    printf("Erreur socket\n");
    return -1;
  } else {
    char * hostname = "127.0.0.1";
    struct sockaddr_in sin = init_sockaddr(hostname, PORT);

    int connexion = connect(sock, (struct sockaddr *)&sin, sizeof(sin));
    if(connexion == -1) {
      printf("Erreur connect()\n");
      return -1;
    } else {

      pthread_t thread;
      pthread_create(&thread, NULL, boucle_recv, (void*)&sock);
      pthread_detach(thread);

      FILE * flux_write = fdopen(sock, "w");
      while(1) {
	char buf[4];
	printf("> ");
	scanf("%s", buf);
        envoyer(buf, sock, flux_write);
      }
    }


  }
    return 0;
}
Calculatrice::Calculatrice(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::Calculatrice)
{

    ui->setupUi(this);
    connect(ui->addTab, SIGNAL(clicked()), this, SLOT(creerTab()));


    mapper = new QSignalMapper();

    connect(ui->BtBack, SIGNAL(clicked()), this, SLOT(effacer()));
    connect(ui->BtVider, SIGNAL(clicked()), ui->entreeTxt, SLOT(clear()));
    connect(ui->BtEnvoyer, SIGNAL(clicked()), this, SLOT(envoyer()));
    // PAVE NUMERIQUE
    connect(ui->Bt0, SIGNAL(clicked()), mapper, SLOT(map()));
    mapper->setMapping(ui->Bt0, "0");
    connect(ui->Bt1, SIGNAL(clicked()), mapper, SLOT(map()));
    mapper->setMapping(ui->Bt1, "1");
    connect(ui->Bt2, SIGNAL(clicked()), mapper, SLOT(map()));
    mapper->setMapping(ui->Bt2, "2");
    connect(ui->Bt3, SIGNAL(clicked()), mapper, SLOT(map()));
    mapper->setMapping(ui->Bt3, "3");
    connect(ui->Bt4, SIGNAL(clicked()), mapper, SLOT(map()));
    mapper->setMapping(ui->Bt4, "4");
    connect(ui->Bt5, SIGNAL(clicked()), mapper, SLOT(map()));
    mapper->setMapping(ui->Bt5, "5");
    connect(ui->Bt6, SIGNAL(clicked()), mapper, SLOT(map()));
    mapper->setMapping(ui->Bt6, "6");
    connect(ui->Bt7, SIGNAL(clicked()), mapper, SLOT(map()));
    mapper->setMapping(ui->Bt7, "7");
    connect(ui->Bt8, SIGNAL(clicked()), mapper, SLOT(map()));
    mapper->setMapping(ui->Bt8, "8");
    connect(ui->Bt9, SIGNAL(clicked()), mapper, SLOT(map()));
    mapper->setMapping(ui->Bt9, "9");
    //OPERATEUR
    connect(ui->BtPlus, SIGNAL(clicked()), mapper, SLOT(map()));
    mapper->setMapping(ui->BtPlus, "+");
    connect(ui->BtMoins, SIGNAL(clicked()), mapper, SLOT(map()));
    mapper->setMapping(ui->BtMoins, "-");
    connect(ui->BtVirgule, SIGNAL(clicked()), mapper, SLOT(map()));
    mapper->setMapping(ui->BtVirgule, ",");
    connect(ui->BtSigne, SIGNAL(clicked()), mapper, SLOT(map()));
    mapper->setMapping(ui->BtSigne, "NEG");
    connect(ui->BtMult, SIGNAL(clicked()), mapper, SLOT(map()));
    mapper->setMapping(ui->BtMult, "*");
    connect(ui->BtDiv, SIGNAL(clicked()), mapper, SLOT(map()));
    mapper->setMapping(ui->BtDiv, "/");
    connect(ui->BtExpression, SIGNAL(clicked()), mapper, SLOT(map()));
    mapper->setMapping(ui->BtExpression, "'");
    connect(ui->BtPuissance, SIGNAL(clicked()), mapper, SLOT(map()));
    mapper->setMapping(ui->BtPuissance, "^");
    connect(ui->BtEspace, SIGNAL(clicked()), mapper, SLOT(map()));
    mapper->setMapping(ui->BtEspace, " ");
    //FONCTION
    connect(ui->BtFactoriel, SIGNAL(clicked()), mapper, SLOT(map()));
    mapper->setMapping(ui->BtFactoriel, "!");
    connect(ui->BtModulo, SIGNAL(clicked()), mapper, SLOT(map()));
    mapper->setMapping(ui->BtModulo, "%");


    connect(mapper, SIGNAL(mapped(const QString &)), this, SLOT(ecrire(const QString &)));
    creerTab();



}