Solved

CSocket and worker thread

Posted on 2003-11-27
6
695 Views
Last Modified: 2013-11-20
I create CSocket (damn it) in worker thread. It fails to function. I found in one of questions
http://www.experts-exchange.com/Programming/Programming_Languages/MFC/Q_10299360.html
that it's because worker thread does not have message loop and as one of remedies recommends adding message loop to worker thread.
My question is
1. Does it really help by adding message loop (here I think meant message queue?)
2. If it solves CSocket mystery, how Do I add message queue to worker thread
0
Comment
Question by:amakalski
[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
  • 3
  • 2
6 Comments
 

Author Comment

by:amakalski
ID: 9834437
...and after adding message queue to my worker thread Do I need to pick any messages from the queue? (I don't really want to pick any messages, the msg queue I only need to accomodate CSocket appetite).
0
 
LVL 12

Assisted Solution

by:migel
migel earned 200 total points
ID: 9835560
Hi!
What reason in using ASync sockets in the WORKER thread????
May be you can use sync. sockets?
0
 

Author Comment

by:amakalski
ID: 9838185
No, I use CSocket which is sync. socket I mean it blocks when I call Receive.
0
Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

 
LVL 12

Expert Comment

by:migel
ID: 9838256
But it is normal :-)
since you call receive in the working thread then UI will not freeze.
Or you need add timeout support?
0
 
LVL 4

Accepted Solution

by:
inox earned 200 total points
ID: 9838310

CSocket (damn it!!) is designed to be used in mainthread preventing the need to do multithreading.
This doesn't mean that it can't be used in treads but its a bit obscure to do so.

Its not very much difficult to use the Windows Socket API instead of CSocket MFC but it depends on what's to do

It's somewhat extensive to outline both, do you think you can choose one solution?
- singlethreaded with CSocket
- multithreaded with CSocket
- multithreaded with Socket API
0
 

Author Comment

by:amakalski
ID: 9838431
Oh, well,
I will give up CSocket at all. Recently I digged up some of my old code and found wrapper classes around Winsock API. These classes will help me to get rid of MFC CSocket and have another advantage - less MFC dependency !

P.S Thanks everybody, I will split points
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

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.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

626 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