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 8894643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:33:13+00:00 2026-06-14T23:33:13+00:00

I am writing multi-clients chat program of C++, I have a few problems that

  • 0

I am writing multi-clients chat program of C++, I have a few problems that I can’t solve.

1. When a user comes in, the server will Accept() the client, then assign a socket id to the client. When the client disconnect, another client comes in, after the server Accept() it, the client will get another socket ID. I want to reuse the socket id, but the Accept() will give a larger socket id than previous socket id of previous client. So, How can I assign the socket id to each client?

2. I use select(fdmax + 1, &read_fds, NULL, NULL, NULL) and for(i = 0; i <= fdmax; i++) to scan each every exist connection, and client can use tenlet connect to my server. In addition to chatting, client can run commands(like ls, cat) on my server, my server will use fork() and dup() send the result to the client. Here is a problem, if the user assigns a new PATH of environment variable, the PATH of other clients will be changed too. How can I avoid this, every clients should have their own default PATH value?

  • 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-06-14T23:33:15+00:00Added an answer on June 14, 2026 at 11:33 pm

    For the first problem: you’re probably not closing (close(2)) the socket (even if the client disconnects). Although I can’t find it in the POSIX spec, typically accept(2) (and pretty much anything creating file descriptors) will return the smallest possible descriptor.

    That being said, there’s likely no reason to tie your application to this. Your application should treat accept as if it could return anything.

    For the second problem, you should change the PATH after you fork, right before you exec.


    All this aside, I notice you’re tagging your question C++: you should take a look at the mighty asio.

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

Sidebar

Related Questions

I am writing a multi-threaded Java program that generates lot of random numbers. Additional
I have a (game) server that I am writing in python (3.1), and have
I am writing a multi-agent system in 2APL. In my agent file, I have
I am on MacOSX. I am writing a multi threaded program. One thread does
I have a multi-project ASP.NET + C# solution. I was planning on writing a
Writing htaccess that allows me to remove index.php from the URL can confuse search
I'm trying to build a server that will handle many concurrent connections to iPhone
Whats the best approach for writing data to a file that will be picked
I'm writing a multi-threaded server application in Java. Everything works fine , but there's
I'm currently writing a multi-process network game server (one gatekeeper process which tells players

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.