Solved

Multithreading advice, please...

Posted on 1998-10-13
3
214 Views
Last Modified: 2013-11-19
Hi!!
  I'm finished a client-server application, which knows chat,
database access, whiteboard and so on, but the server is not multithreading. I have the next situation:
 - there is a class, which is derived from CSocket class, and manage the connection with the clients - the client class
 - I have one class, the Doc class, who receive on a specified port the clients, which are trying to access the server - the server class

Each client object have access to some data from the "server" class and vice-versa (each client have a pointer to the server class)
    I have some ideas to modify this program to obtain a multithreaded application:
 - to make a multiple inheritance when I derive the client class by using the CSocket and CWinThread classes
 - to use  worker threads for each client, and transfer to the treads a pointer to the server class
...
Please tell me, how can do  easier the multithreading in this situation??
0
Comment
Question by:visualc
3 Comments
 
LVL 2

Expert Comment

by:rayb
ID: 1323246
Hmmm...  Here's a real general comment...  Nearly every client/server application that I've ever worked on that relied on sockets, used a threading model like this:
The server has a main thread, which 'listens' for clients.  Once a client is detected a new thread is launched to service that client.
0
 

Accepted Solution

by:
seanowens earned 70 total points
ID: 1323247
Your question is not very clear or detailed.  Try to explain further what you need to know.  I don't think you're going to need to use multiple inheritance to solve your problem.  The comment from rayb is accurate.  The basic layout is
a) The main server thread listens on the socket
b) When a client connects to the server socket, the server thread wakes up, creates a new socket, accepts the connection, and does whatever else is necessary to set up the socket.  At THIS point the main server thread creates a new instance of the client manager object, puts the newly created socket into the client manager, and then spins off another worker thread.  You are going to need to do some kind of locking or user defined messages to communicate between server and client-manager, to avoid two threads accessing the same piece of code at the same time.  I suspect user defined messages will be better but thats really just a guess.  If you want more information contact me at player@envirolink.org.  
0
 

Author Comment

by:visualc
ID: 1323248
Hi, seanowens!!

I sent to you an e-mail!!!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now