So this is my problem:
I still have this problem about client not connecting to the server and server not receiving anything.
WORD wVersionRequested = MAKEWORD(2, 2);
WSAStartup(wVersionRequested, &wsaData);
[...]
printf("Starting %s Login Core on %s:%d.\n", CM->getString(CM->SERVER_NAME).c_str(), CM->getString(CM->SERVER_IP).c_str(), CM->getNumber(CM->SERVER_PORT));
InitializeCriticalSection(&gCriticalSection);
s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof(on));
err = ioctlsocket(s, FIONBIO, &iMode);
sin.sin_family = AF_INET;
sin.sin_port = CM->getNumber(CM->SERVER_PORT);
sin.sin_addr.s_addr = inet_addr(CM->getString(CM->SERVER_IP).c_str());
switch (sin.sin_addr.s_addr)
{
case INADDR_NONE:
printf("[!] Input IP Address is NONE!\n");
break;
case INADDR_ANY:
printf("[!] Input IP Address is ANY!\n");
break;
}
if (err = ::bind(s, (SOCKADDR*)&sin, sizeof(sin)) == SOCKET_ERROR)
{
printf("[!] Binding error (%ld).\n", WSAGetLastError());
return 1;
}
err = listen(s, SOMAXCONN);
if (err == SOCKET_ERROR)
{
printf("[!] Listening error (%ld).\n", WSAGetLastError());
return 1;
}
int fromlen;
while (true)
{
fromlen = sizeof(from);
sock_accept = accept(s, (struct sockaddr*)&from, &fromlen);
if (sock_accept != INVALID_SOCKET)
{
THREAD_STRUCT* th_struct = new THREAD_STRUCT;
th_struct->Socket = sock_accept;
th_struct->MySQLHandler = DB;
th_struct->ChannelsInfo = ChannelsInfo;
th_struct->ThreadHandle = CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)WinSockThread, th_struct, NULL, &th_struct->SocketRead);
}
Sleep(100);
}
WSACleanup();
}
The server is local, so the IP is correct (127.0.0.1) for the client AND the server.
Client says "unable to connect", my server does not even know there's an incoming connection ( what the hell? ).
I tryed to connect to the server trough putty, raw socket on my server IP:Port and the result is "Connection Refused".