Solved

Multithreading advice, please...

Posted on 1998-10-13
3
215 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
method notes when mouse over in eclipse 5 83
wordappend challenge 8 149
unix example issues 18 75
Capture logon name 13 42
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

920 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

13 Experts available now in Live!

Get 1:1 Help Now