problema winsock imposible (desplácese hacia abajo primer post anterior)

  • Bozebo
  • Expert
  • Expert
  • Avatar de Usuario
  • Registrado: Feb 15, 2006
  • Mensajes: 709
  • Loc: 404
  • Status: Offline

Nota Enero 7th, 2011, 12:53 pm

Por favor, desplácese hacia abajo para mi próximo post.


Hola, tengo una lista de punteros a objetos stl y quiero agregar un nuevo objeto al final de la lista. Debe ser bastante sencillo, pero algo va mal porque Visual Studio es que me da dos errores en la misma línea así:
Quote:
C2059 de error: error de sintaxis:)


En la línea con push_back. He aquí un extracto de mi código:

CPP Código: [ Select ]
//definition of the class
class ribClient{
   char inBuff[4096], outBuff[4096];
   bool loggedIn;
   SOCKET clientSock;
 
  //playable character associated with this client
   ribPlayer player;
 
public:
  ribClient(SOCKET clientUseSock){
    clientSock = clientUseSock;
 
    //add join response to outBuff containing version request etc.
  }
 
  SOCKET getClientSock(){ return clientSock; }
};
 
 
//definition of my list:
//stl list of clients
std::list<ribClient*> clientList;
 
//problem function:
//adds a new client
void addClient(SOCKET clientUseSock){
  //add a new client and set which socket they use
  clientList.push_back(new(ribClient(clientUseSock))); //error is on this line
}
 
  1. //definition of the class
  2. class ribClient{
  3.    char inBuff[4096], outBuff[4096];
  4.    bool loggedIn;
  5.    SOCKET clientSock;
  6.  
  7.   //playable character associated with this client
  8.    ribPlayer player;
  9.  
  10. public:
  11.   ribClient(SOCKET clientUseSock){
  12.     clientSock = clientUseSock;
  13.  
  14.     //add join response to outBuff containing version request etc.
  15.   }
  16.  
  17.   SOCKET getClientSock(){ return clientSock; }
  18. };
  19.  
  20.  
  21. //definition of my list:
  22. //stl list of clients
  23. std::list<ribClient*> clientList;
  24.  
  25. //problem function:
  26. //adds a new client
  27. void addClient(SOCKET clientUseSock){
  28.   //add a new client and set which socket they use
  29.   clientList.push_back(new(ribClient(clientUseSock))); //error is on this line
  30. }
  31.  


Parece que mi compilador (Visual Studio 2008) está esperando otra cosa, ya sea nueva o el constructor de cliente, pero no veo por qué. Creo que han hecho esto muchas veces en g + + sin problemas en absoluto.

¿Qué estoy haciendo mal / ¿cómo puedo hacer lo que quiere Visual Studio?
  • Anonymous
  • Bot
  • No Avatar
  • Registrado: 25 Feb 2008
  • Mensajes: ?
  • Loc: Ozzuland
  • Status: Online

Nota Enero 7th, 2011, 12:53 pm

  • spork
  • Brewmaster
  • Silver Member
  • Avatar de Usuario
  • Registrado: Sep 22, 2003
  • Mensajes: 6130
  • Loc: Seattle, WA
  • Status: Offline

Nota Enero 7th, 2011, 4:24 pm

Bozebo escribió:
Edición: no importa que estaba siendo estúpida, yo solía nueva (className (valor)) en lugar de className nuevo (valor)
Necesidad de ir a buscar un bocadillo :D


Y una cerveza :beerchug:
The Beer Monocle. Classy.
  • Bozebo
  • Expert
  • Expert
  • Avatar de Usuario
  • Registrado: Feb 15, 2006
  • Mensajes: 709
  • Loc: 404
  • Status: Offline

Nota Enero 7th, 2011, 6:18 pm

spork escribió:
Y una cerveza :beerchug:


Maby si puedo solucionar este problema siguiente :cry:

Esta cifra a cabo una:
CPP Código: [ Select ]
        //read up to 1024 bytes into tempBuffer
        bytesRecvd = recv(tempSocket,tempBuffer,512,0);
        //if there was an error or no bytes were received (connection closed)
        if(WSAGetLastError() != 0 || bytesRecvd < 1){
          printf("client disconnected: %d/%d\n",bytesRecvd,WSAGetLastError());
          //remove the client
          removeClient(tempItMapClient);
          continue; //continue looping through the fd_set
        }
  1.         //read up to 1024 bytes into tempBuffer
  2.         bytesRecvd = recv(tempSocket,tempBuffer,512,0);
  3.         //if there was an error or no bytes were received (connection closed)
  4.         if(WSAGetLastError() != 0 || bytesRecvd < 1){
  5.           printf("client disconnected: %d/%d\n",bytesRecvd,WSAGetLastError());
  6.           //remove the client
  7.           removeClient(tempItMapClient);
  8.           continue; //continue looping through the fd_set
  9.         }



Y ahora mira esta captura de pantalla.....
Imagen

Tan pronto como cualquier cliente envía incluso un byte para el servidor que están desconectados.

El primer intento de unirse es mi aplicación cliente (que envía PING cuando se puede) y el segundo me es cromo apuntando a localhost: 272727

Línea 5 en el código anterior no es posible que imprimir "el cliente se desconectó: N / 0" de ninguna manera o forma!

Además, estoy imprimiendo la información de winsock wsData después WSAStartup ( MAKEWORD (2, 2) E wsData), pero ¿por qué dice Winsock 2.0 en lugar de 2,2?

¿Qué :evil:

Publicar Información

  • Total de mensajes en este tema: 3 mensajes
  • Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 172 invitados
  • No puede abrir nuevos temas en este Foro
  • No puede responder a temas en este Foro
  • No puede editar sus mensajes en este Foro
  • No puede borrar sus mensajes en este Foro
  • No puede enviar adjuntos en este Foro
 
 

© 2011 Unmelted, LLC. Ozzu® es una marca registrada de Unmelted, LLC