Solved

C++ multithread Server

Posted on 2000-03-16
1
569 Views
Last Modified: 2008-01-09
What's the most efficient way to implement a C++ multithread server using sockets?

I have a server that has an infinite loop. This loop has an accept socket function, and when a client connects with the server socket, the server creates a thread and relays the communication to this thread. Then, the server returns to the  loop.

Are there any more efficient ways to implement this functionality?
0
Comment
Question by:Lucsat
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 1

Accepted Solution

by:
karlww earned 100 total points
ID: 2625686
I assume you are refering to a console application in blocking mode.  If so, you got it;

while (1)
{
   SOCKET sa = accept(m_s,
                      (sockaddr *) &sai,
                      &nSize);
   // send sa to thread for processing
}

You can use non-blocking sockets if using WinSock, which takes more than the 1000 character this is limited to.

Good books on WinSock, number 1 covers blocking, 2 both but mainly nonblocking after a couple chapters.
1. Internetworking With TCP/IP Volume III - WinSock Version.

2. Windows Sockets Network Programming.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question