Solved

CSocket and worker thread

Posted on 2003-11-27
6
677 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
  • 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

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…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

706 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

19 Experts available now in Live!

Get 1:1 Help Now