void* thread(void* arg)
{
  std::cout << "Hi" << std::endl;
  return arg;
}

void clientFunc(TCPSocket* s)
{
  pthread_t pid;

  pthread_create(&pid, NULL, &thread, NULL);
  pthread_join(pid, NULL);
}

int main()
{
  ServerSocket s(4543);

  try {
      while(1)
      {
          clientFunc(s.accept());
      }
  }catch(Error& err) {
      err.what();
  }
}

My question is, how can I create threads for every client that connects ,every thread to do something else?

I encourage you (or someone else) to put a simple TCPSocket example here:

http://programmingexamples.net/index.php?title=CPP/TCPSocket

then we can address your specific problem. You say "every thread to do something else". Does that mean you want different functionalities for specific clients? I'd say there has to be some finite set of client ids or types then, you probably need a thread1(), thread2(), etc.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.