Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

MFC CSocket vs. thread + CAsyncSocket

Posted on 2005-03-25
7
Medium Priority
?
6,967 Views
Last Modified: 2013-11-25
I am designing a server for networked card games with MFC.  The server consists of a heirarchy of "servlets": each room will exist on a separate process, with a separate server socket, and an incoming and outgoing message queue.  Each room consists of several tables, which may also be described this way.

Therefore, my abstraction contains a "ServerThread", which manages a (server) CAsyncSocket, toggling non-blocking IO when appropriate.  The server thread would also pump messages to and from client sockets, and ocasionally respond to client messages.  I am debating whether to also use CAsyncSockets for client sockets.  It would obviously be difficult to manage the IO state for all client sockets.  I think it would be much simpler to have a "ClientThread", which would use an ASyncSocket that always blocks (not sure if it would actually work otherwise).  Is it worth it, or should I just use plain CSockets?

It should be noted that this server thread does not need a Windows message pump, as it only responds to socket messages.

Also, are there any good open-source MFC compatible ThreadPools and/or SocketPools out there?

Thanks,

Shawn Curry
0
Comment
Question by:ShawnCurry
  • 3
  • 3
7 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 13636061
CSocket class is not used in professional programs. Since this class is synchronous, it is used mostly by beginner programmers giving them simple interface which they can handle.
The choice is between using CAsyncSocket or socket API. I don't like MFC sockets support and prefer sockets API, but this is my personal opinion.
0
 
LVL 5

Expert Comment

by:vadivhere
ID: 13643321
Why you don't like mfc sockets AlexFM ? Is there any reason for that?

Vadivel Kumar
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 13643379
CSocket or CAsyncSocket ?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Expert Comment

by:vadivhere
ID: 13643393

  " I don't like MFC sockets support and prefer sockets API, but this is my personal opinion."   ???

    Why you dont like mfc sockets??

   
0
 
LVL 48

Accepted Solution

by:
AlexFM earned 1400 total points
ID: 13643510
Using MFC socket classes hides internal implementation of sockets raw API and managing of worker threads required for this. This makes program non-portable, while sockets are supposed to work in any operating system. Personally, I don't like to use MFC serialization code with sockets. I prefer to have full control rather than rely on MFC support. But this is individual preference. You can write good program using CAsyncSocket class. For example, MFC HTTPSVR Sample is full-featured WEB server written using CAsyncSocket class. This proves that this class is quite good.
I prefer to use MFC only for Windows-related tasks. I don't like the following MFC classes:
1) Containers (it's better to use STL).
2) File operations (I am quite happy with CreateFile)
3) Sockets (I prefer socket API)
4) COM support (ATL is better).

I know that most MFC developers have the same opinion about STL and ATL. About sockets - I don't suggest you to follow my choice, you can decide this yourself.
0
 
LVL 5

Expert Comment

by:vadivhere
ID: 13649218
If you want to hold 14meg file, do you think Containers are worth it on that case?
-- Just to know your view as you have expressed a resonable thought about MFC --

Cheers
Vadivel Kumar
0
 
LVL 3

Author Comment

by:ShawnCurry
ID: 13659090
Thank you for your input.  I have learned a great deal about Microsoft's support for sockets and threads since first asking the question.  I have elected not to use MFC; as the user interface will likely be written in Java, and I need slightly finer-grained control than MFC provides.  I will definately need a ThreadPool, therefore I am designing my own Java-like sockets and concurrency APIs.

Thanks again,

Shawn
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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 …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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 is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

571 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