Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6980923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:05:21+00:00 2026-05-27T18:05:21+00:00

Note: I am mixing some C & C++ but it shouldn’t be too confusing.

  • 0

Note: I am mixing some C & C++ but it shouldn’t be too confusing.

Connected clients are added to a multimap (might aswel have been a map, I know ^^).

The multimap

typedef std::multimap<std::string, SOCKET> clientMap;
typedef std::pair<clientMap::iterator,
                    clientMap::iterator>
                                    clientIters;
clientMap clientmap;
clientIters clientByID(std::string clientID)
{
    return clientmap.equal_range(clientID);
}

Adding a client (each client runs in it’s own thread)

//Add clientID to map of clients
if(clientAdded == false)
{
    std::stringstream ss;
    ss << lpParam; //Use socket# as the unique ID
    clientID = ss.str();
    clientmap.insert(std::pair<std::string,SOCKET>(clientID,sock));
    clientAdded = true;
}
//Client wasn't added correctly!
if(clientID == "" || clientAdded == false)
{
    std::cout << "Problem adding client" << std::endl;
}

Server waits for client messages with a blocking recv() call

ret = recv(sock, szBuff, DEFAULT_BUFFER, 0);
if (ret == 0)        // Graceful close
    break;
else if (ret == SOCKET_ERROR)
{
    printf("recv() failed: %d\n", WSAGetLastError());
    removeUser(clientID);
    break;
}

removeUser() function

void removeUser(std::string clientID)
{
    std::cout << "Going to try and remove client: " << clientID << std::endl;

    //Remove client
    clientIters iters = clientByID(clientID);
    clientMap::iterator it = iters.first;
    while(it != iters.second)
    {
        clientmap.erase(it++);
        std::cout << "removed client: " << it->first << std::endl;
    }

    //Show remaining clients
    std::cout << "clients left:" << std::endl;
    for (clientMap::iterator it = clientmap.begin(); it != clientmap.end(); ++it)
    {
        std::cout << it->first << std::endl;
    }
}

All of this is working fine if I close a client that was connected to either my local IP or external IP (directly).

recv() failed: 10054
Going to try and remove client 0000008C
removed client 0000008C
clients left:
00000084
00000088

But if I put a proxy inbetween (using proxifier), the server thinks the connection is still active or something because the server doesn’t do anything when I close the client. It just sits there.. waiting for nothing.

I’m using this socket class as a base but it’s pretty heavily modified by now.

How can I make sure a closed client is definitely removed from the multimap?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T18:05:22+00:00Added an answer on May 27, 2026 at 6:05 pm

    Could you store some state for each connection? like the last time something was received?

    You could then periodically loop through your active connections and prune any that haven’t sent anything for a long time, as the connection is more then likely stale.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Note: This might seem like a Super User question at first, but please read
Note that I am not asking which to choose (MVC or MVP), but rather
Note The question below was asked in 2008 about some code from 2003. As
I am mixing some C and C++ libraries and have only a single pointer
Note: It was tough deciding whether this belonged here or ServerFault, but it seemed
NOTE: I have updated this since originally asking the question to reflect some of
Note: The answers & comments below reflect the state of legacy browsers in 2009.
Note: This question refers to a Rails project with Sass & Compass. Using the
note: question title is change as discussed in this meta Q&A I'm using the
</p> is only required in XHTML but not in HTML. Some times you have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.