impossible winsock problem (scroll down past first post)

  • Bozebo
  • Expert
  • Expert
  • User avatar
  • Posts: 709
  • Loc: 404

Post 3+ Months Ago

Please scroll down to my next post.


Hi, I have a stl list of object pointers and I want to add a new object to the end of the list. It should be fairly simple but something is going wrong because visual studio is giving me 2 errors on the same line thusly:
Quote:
error C2059: syntax error : ')'


On the line with push_back. Here is an extract from my code:

CPP Code: [ 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.  


It looks like my compiler (visual studio 2008) is expecting something else from either new or the client constructor, but I don't see why. I think have done this many times in g++ with no problems at all.

What am I doing wrong/how do I do what visual studio wants?
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • spork
  • Brewmaster
  • Silver Member
  • User avatar
  • Posts: 6252
  • Loc: Seattle, WA

Post 3+ Months Ago

Bozebo wrote:
Edit: nevermind I was being stupid, I used new(className(value)) instead of new className(value)
Need to go get a sandwich :D


And a beer :beerchug:
  • Bozebo
  • Expert
  • Expert
  • User avatar
  • Posts: 709
  • Loc: 404

Post 3+ Months Ago

spork wrote:
And a beer :beerchug:


Maby if I can fix this next problem :cry:

Figure this one out:
CPP Code: [ 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.         }



And now look at this screenshot.....
Image

As soon as any client sends even 1 byte to the server they are disconnected.

The first join attempt is my client app (which sends PING when it can) and the 2nd is me pointing chrome to localhost:272727

Line 5 in the above snippet CANNOT possibly print "client disconnected: N/0" in any way, shape or form!

Also, I am printing winsock information from wsData after WSAStartup(MAKEWORD(2, 2), &wsData) but why does it say winsock 2.0 instead of 2.2?

What :evil:

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 63 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.