WINSOCK problem

I wrote a winsock server a while back. I have not touched the code at all in months and today I ran the binary and it was not accepting new connections. I loaded up code blocks and used the debugger and it appears to jam on the accept function. Has anyone else had this issue and know how to solve it

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/* The acceptThread is in charge of accepting connections I suppose this is our main gate
 *from the outside world to our game */
DWORD WINAPI acceptThread(LPVOID lpParam)
{
    while(1)
    {
        int cliaddr_len = sizeof(client_addr);
        client = accept(sock, (struct sockaddr *) &client_addr, &cliaddr_len);
        if (client != INVALID_SOCKET)
        {
            PlayerHandler::newPlayerClient(client);
        }
        else
        {
            cout << "Socket error! - " << WSAGetLastError();
        }
        cout << "test";
    }

    return 0;
}


The server was working just fine earlier
Last edited on
your problem is struct

 
client = accept(/*Listen Socket, appears yours is correct, make sure.*/, (/*No Struct*/SOCKADDR*)&addr, &addrlen)
Last edited on
It was not. I changed the port and it seems to work now. I don't know why I suddenly had problems with port 5555 it was not being used as my program was written to detect that.
I hope client_addr is of type struct sockaddr_in.

If that's ok, there's nothing wrong with that code. You have to show us how you setup the socket.
What are you using to test this functionality OP? Is it possible that you made a change in that component and you don't remember? Your application isn't "jamming" on the call to accept. What it's doing is waiting until it gets a valid request on the socket you designate. What did you change the port to (out of curiosity)?
That's what I meant when I said jamming. It is looping around waiting for a new client that needs to be accepted. I changed it from port 5555 to 5556 and it now works fine. What I find strange is I disabled Windows firewall and still had the same issue. It was only changing the port that fixed the problem. The port was also free before my application began to listen on it. So it is confusing why it broke like that. It is a bit worrying because if in a few months when my game is released and is active and this happens this could make the game lose players.
Last edited on
Unless you intentionally changed the sockets blocking mode to non-blocking with "ioctlsocket()" accept should not be looping, it should be waiting quietly. Also important to note, if the connection succeed on port 5556 then what ever was trying to connect was using that port. The application doesn't say "Oh well 5555 isn't there but 5556 is close enough". You have to tell what ever is connecting to your server to connect on that port specifically.

LONG SHOT: You aren't by any chance using the "services" file under C:\Windows\System32\drivers\etc where some one may have made an alteration are you?
Topic archived. No new replies allowed.