?
Solved

MFC CSocket vs. thread + CAsyncSocket

Posted on 2005-03-25
7
Medium Priority
?
6,888 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
[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
  • 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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…

771 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