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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T12:34:33+00:00 2026-05-18T12:34:33+00:00

I have a server client app written in C++ on Linux. When a client

  • 0

I have a server client app written in C++ on Linux. When a client connects to my server, the server spawns a thread that waits for the client to send the server commands to execute. the commands are OS dependent. the thread that the client is talking to the server on, calls global functions that perform the required command that the client wants. So I have to have two functions for every OS depended command the client sends to the server to be executed. All of these global functions are defined in the same header that the main thread function is. It’s getting a bit messy with all of these functions for different OS’s. My idea is to write two classes that are called WindowsFuncs and LinuxFuncs that have static member functions that perform the required command for that OS the class was designed for. What are some of stackoverflows ideas on how to clean my logic?

  • 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-18T12:34:33+00:00Added an answer on May 18, 2026 at 12:34 pm

    This doesn’t sound like a threading problem.
    Sounds like you can use simple inheritance.

    Using something like

    abstract class OSMethods {
      void listDir();
    }
    
    class OSMethodsLinux : OSMethods {
      void listDir() { system.exec("ls"); }
    } 
    class OSMethodsWin : OSMethods {
      void listDir() { system.exec("dir"); }
    }
    

    Then server client processing code has method like

      void accept(Socket s, OSMethods m) {
         s.readCommand();
         m.listDir();  // or whatever
      }
    

    Make sure you pass correct instance to accept of either Linux or Win class.
    So no static methods.

    Generally I’ve found that you will need no static methods in your programs (except main) unless you are doing clever stuff, most things just don’t need them and they lead to less flexible design.

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

Sidebar

Related Questions

I have Android client app that communicates with server using Socket . On my
I have a DDE client app which connects to the DDE server app by
I've written a client that connects to a server via a named pipe, and
I have client/server application where the client app will open files. Those files get
i have client-server app, I'm managing connections with Threads and handlers inside app, but
I have client-server app. Client on C++, server on Java. I am sending byte-stream
We have client server based app which saves user related data into a zip
I have a simple client-server app on android. the android service communicates with the
I'm writing chat client/server app with c# and I have problem with threading. I
I'm developing a new client-server app (.Net) and have up until now been using

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.