Hi, everyone. Most people know when you are trying to connect the server with a lot of people, the server can not respond to you or something might go wrong. This example is same for warp too. Webzen did something about this too and I'd like to share it with you.
What are exactly are we doing?
If the client can not connect to the server, the client will wait one second to connect the server again.
Open NetStream.cpp. Find Connect function and replace with this
bool CNetworkStream::Connect(const CNetworkAddress& c_rkNetAddr, int limitSec)
{
Clear();
m_addr = c_rkNetAddr;
m_sock = socket(AF_INET, SOCK_STREAM, 0);
if (m_sock == INVALID_SOCKET)
{
Clear();
OnConnectFailure();
return false;
}
DWORD arg = 1;
ioctlsocket(m_sock, FIONBIO, &arg); // Non-blocking mode
if (connect(m_sock, reinterpret_cast<PSOCKADDR>(&m_addr), m_addr.GetSize()) == SOCKET_ERROR)
{
int error = WSAGetLastError();
// If something went wrong, the client will wait one second to connect the server again.
// Of course, it will clear and setting up everything again.
if (error != WSAEWOULDBLOCK)
{
Sleep(1000);
Clear();
m_sock = socket(AF_INET, SOCK_STREAM, 0);
if (m_sock == INVALID_SOCKET)
{
Clear();
OnConnectFailure();
return false;
}
ioctlsocket(m_sock, FIONBIO, &arg);
if (connect(m_sock, reinterpret_cast<PSOCKADDR>(&m_addr), m_addr.GetSize()) == SOCKET_ERROR)
{
Tracen("error != WSAEWOULDBLOCK");
Clear();
OnConnectFailure();
return false;
}
}
}
m_connectLimitTime = time(NULL) + limitSec;
return true;
}
Best Regards
Ken