Original Post
Hey, I have a server set up and multiple clients can connect, but when one clients force disconnects(closes the window), the server pulls up error 10054, which means the client force disconnected, and the server crashes. Does anyone have any ideas? Maybe you have had a similar problem. Here is most of my server loop.
int FluxServer::CheckEvents()
{
bool Quit = false;
char Buf[1400];
while(Quit == false)
{
ZeroRead();
ZeroWrite();
SetRead(m_ListenSocket);
for(vector<int>::iterator itr = m_SocketList.begin(); itr != m_SocketList.end(); itr++)
{
SetRead(*itr);
}
if((select(50, &m_FlagRead, &m_FlagWrite, NULL, NULL)) > 0)
{
if(CheckFlag(m_ListenSocket) == 1)
{
cout<<"New Connection"<<endl;
FluxConnection Con;
Con = Accept();
AddSocket(Con);
}
for(vector<int>::iterator itr = m_SocketList.begin(); itr != m_SocketList.end(); itr++)
{
if(CheckFlag(*itr) == 1 ) //Does this socket need to be read from
{
//cout<<"reading"<<endl;
int Recv = GetPacket(Buf,*itr);
cout<<"Recvc:"<<Recv<<endl;
//Recv = recv(*itr,Buf,128,0);
if(Recv > 0)
{
cout<<"Message"<<Buf<<endl;
}
if(Recv == 0)
{
cout<<"Disconnecting";
closesocket(*itr);
m_SocketList.erase(itr);
itr--;
}
if(Recv < 0)
{
int Error;
Error = WSAGetLastError();
cout<<"Recv Error"<<Error;
//FluxShutdownWinSock();
return 0;
}
}
if(CheckFlag(*itr) == 0 ) //Does this socket need to be written to
{
}
}