Ver Mensaje Individual
  #3 (permalink)  
Antiguo 24/04/2014, 07:34
Principe_Azul
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: Problema cuando atacan a mi programa C++

Amigo CalgaryCorpus, he aumentado el tamaño del buffer y el bot ya no cae, pero se me ocasiona otro problema, el buffer deja de recibir información y en esta línea:

Código C++:
Ver original
  1. nret = recv(iSocket, recvbuf, 256, 0);

En mi otro código de Python, ese 256 está en 1024... mucha diferencia.

Pego aquí parte del código:

Código C++:
Ver original
  1. while (1) {
  2.         memset(&sendbuf, 0, sizeof(sendbuf));
  3.         memset(&recvbuf, 0, sizeof(recvbuf));
  4.  
  5.         nret = recv(iSocket, recvbuf, 256, 0);
  6.  
  7.         if(nret == SOCKET_ERROR) {
  8.             cout << "Error: No se ha podido conectar con el Servidor" << endl;
  9.             break;
  10.         }
  11.  
  12.         string Ping = string(recvbuf);
  13.         string Pingg = Ping.substr(0,4);
  14.         vector<string> arr;
  15.         arr=split(Ping,"\n");
  16.         string hola;
  17.  
  18.         for(size_t i=0;i<arr.size();i++)
  19.             hola = arr[i].c_str();
  20.             string pepito = hola.substr(0,4);
  21.             int TotalChars = Ping.length();
  22.             string PONG = "PONG " + hola.substr(5,TotalChars) + "\r\n";
  23.             char *probar = strdup(PONG.c_str());
  24.             cout << recvbuf << endl;
  25.             if (pepito == "PING") nret = send(iSocket, probar, strlen(probar), 0);
  26.     }

Espero que me ayuden como siempre!! Gracias amigos.

Las variables tienen ese pésimo nombre, pero luego cuando lo voy terminando al código de a poco, voy renombrando las variables y les asigno un nombre correcto.