?
Solved

C++ multithread Server

Posted on 2000-03-16
1
Medium Priority
?
574 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 300 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

719 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