Skip to main content
gamedev.net
🔒 Locked

mathius20

Started by Mathius20 Jan 19, 2007 at 10:55 PM 0 replies 500+ views
Original Post
Mathius20
Mathius20
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
					{
						
					}
				}


cobru
cobru
Error Number: 10054 Connection reset by peer.

That's not an "error", it's only natural.. it indicates that the remote host has closed connection and you should be getting it unless it's the server the one who closes the connection.

Ran into this 'problem' a few years back, and backthen I realised that it's perfectly normal. I just treated the error (catched the exception, but my code was in delphi), closed the server socket corresponding to the client that 'got away' and went on about my business.

Hope that helps.

Also, some links:

winsock error codes:
http://www.sockets.com/err_lst1.htm#WSAECONNRESET
gamedev usefull article:
http://www.gamedev.net/reference/articles/article1059.asp
Q: How many programmers does it take to write a nice piece of software?A: MORE.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.