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
Solved

CSocket and worker thread

Posted on 2003-11-27
6
683 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

790 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