select() not working ..
im writing networking for my game.. have done quite a lot.. but i cant seem to get the select function to work..
as they say - code speaks louder than words, so here we go.
//-------------------------------------------
fd_set sockset;
SOCKET server;
SOCKET client[8];
int errorcheck;
int cclient;
timeval ttw;
char recbuf[10000];
void Initialise()
{
WORD version = MAKEWORD(2,2);
WSADATA wsaData;
WSAStartup(version, &wsaData);
ZeroMemory(client,sizeof(SOCKET) * 8);
ttw.tv_usec = 100;
server = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
SOCKADDR_IN servad;
servad.sin_family = AF_INET;
servad.sin_addr.s_addr = INADDR_ANY;
servad.sin_port = htons(6552);
bind(server, (LPSOCKADDR)&servad, sizeof(struct sockaddr));
listen(server, 8);
}
// void Update() gets called within an infinte loop - every frame
void Update()
{
FD_ZERO(&sockset);
FD_SET(server,&sockset);
for(int x = 0;x<8;x++)
{
FD_SET(client[x], &sockset);
}
ZeroMemory(recbuf, sizeof(recbuf));
wpacket.update(&gameWorld); // <--- World Packet updates from local server world
if(select(0,&sockset,NULL,NULL,&ttw) > 0)
{
if(FD_ISSET(server, &sockset))
{
findavailsocket();
client[cclient] = accept(server, NULL, NULL);
InitPacket* ipkt = new InitPacket;
ipkt->playerid = cclient;
strcpy(ipkt->mapname,gameWorld.mapname.c_str());
ipkt->sendpkt(client[cclient]);
}
for(int x = 0; x<8; x++)
{
if(FD_ISSET(client[x], &sockset))
{
errorcheck = recv(client[x],recbuf,10000, NULL);
if(errorcheck == WSAENOTCONN)
{
closesocket(client[x]);
ZeroMemory((void *)client[x],sizeof(SOCKET));
break;
}
if(errorcheck == WSAESHUTDOWN)
{
closesocket(client[x]);
ZeroMemory((void *)client[x],sizeof(SOCKET));
break;
}
if(errorcheck == WSAECONNRESET)
{
closesocket(client[x]);
ZeroMemory((void *)client[x],sizeof(SOCKET));
break;
}
Handledata(client[x], recbuf);
}
}
}
}
//------------------------
The problem is, even after ive called connect from the client prog it never trips the select statement. So to make sure it actually was connecting (& ors), i hard coded a accept, recv and send sequence in there which worked fine..
Any ideas/thoughts/suggestions.. im sure its something simple that im too stupid to see :D
Ta in advance guys,
Strik3r
''n'' should be atleast 1 if you want select to work
More specifically:
"n is the highest-numbered descriptor in any of the three sets, plus 1."
Read the manual carefully and see if this helps.
More specifically:
"n is the highest-numbered descriptor in any of the three sets, plus 1."
Read the manual carefully and see if this helps.
I''m sorry, i dont quite understand ?
lol, i feel dumb for asking, but where have i stuffed up ??? what n ?
Strik3r
lol, i feel dumb for asking, but where have i stuffed up ??? what n ?
Strik3r
MSDN::
Parameters:
nfds
[in] Ignored. The nfds parameter is included only for compatibility with Berkeley sockets.
i just tested it anyway and it made no difference..
Strik3r
Parameters:
nfds
[in] Ignored. The nfds parameter is included only for compatibility with Berkeley sockets.
i just tested it anyway and it made no difference..
Strik3r
November 23, 2002 06:16 AM
Well, print out errno and see what it is. Although, I''m unsure if Window''s implementation sets errno, so you may need to try WSAGetLastError(). Most likely, one of the descriptors in the set are invalid. Again, check with the documentation after this to be completely sure. Also, if you plan to port later, you should note that *BSD, Linux, and MacOSX implement sockets entirely.
hah.. its windows only.
ill check for an error message.. but something tells me its just timing out...
gimme 2 min
ill check for an error message.. but something tells me its just timing out...
gimme 2 min
i checked whether or not select was returning SOCKET_ERROR - if it does, then your sposed to use WSAGetLastErr().. but it didnt.. :\ (in fact, im sure i already checked that a long time ago)
im still stumped
im still stumped
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement