Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

MFC: CSocket

Posted on 1998-01-12
3
Medium Priority
?
793 Views
Last Modified: 2013-11-20
Basically I am coming from using the native windows api and the native winsock api so please bear with me.  

This is my first mfc application.

I want to have an mfc application use the CAsyncSocket class to listen for connections.  And when various network events happen such as FD_ACCEPT, it to send a message to the window so that I can accept the connection.  But how can I get it to do this?  There doesn't seem to be any functionallity in the class which lets me tell it to notify this window.  I have tried using the WSAAsyncSelect to specify the m_hWnd member of the window class to notify me of FD_ACCEPT events, but it doesn't work.  It could be a problem with the way I try and receive the message.  I added the ON_MESSAGE(FD_ACCEPT,OnAccept) statement to the message map for that window.  Is that right? Can CAsyncSocket do this for me?  Any help would be greatly appreciated.
0
Comment
Question by:tlsoftware
[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 Comments
 

Accepted Solution

by:
Yores earned 100 total points
ID: 1313946
Hi,

    I am also new in writing CSocket program with MFC.
    Let's share our experience.
    In you case, you said that you don't know which function
is active when a call connect to your computer(server).
    Actually, there are a function handle this case :

CListeningSocket::CListeningSocket(CServerDoc* pDoc)
{
      m_pDoc = pDoc;
}

/////////////////////////////////////////////////////////////////////////////
// CListeningSocket Overridable callbacks

void CListeningSocket::OnAccept(int nErrorCode)
{
      CSocket::OnAccept(nErrorCode);
      m_pDoc->ProcessPendingAccept();
}

    As shown, a function of CSocket::OnAccept() will active
when someone connect to your program.
    For more detail about this source code, please see the
sample file in visual c++ package.


Yores
0
 

Author Comment

by:tlsoftware
ID: 1313947
I have been looking at the same example.  CListenSocket is a class defined by the example in the source file lstnsock.cpp.  But I still can't figure out how the window knows when a connection is accepted.  Nowhere does it seem to specify: hey send this message here.  There is an OnAccept function, but who calls that?  If you know what I am talking about and figure it out, it would help me out a lot!
0
 
LVL 4

Expert Comment

by:jtwine100697
ID: 1313948
  If you are wondering how to get the notification messages, you do not get them.  The CAsyncSocket class creates its own (hidden) window to catch the async notification messages, it then calls the OnXxxx() functions defined in the class.

   The ideal way to use this class is to derive a new class from it, and override the OnXxxxx() functions (CAsyncSocket::OnAccept(), CAsyncSocket::OnSend(), etc).

   When a connection is ready to be accepted, the Winsock API sends the message to the CAsyncSocket object, which in turn calls the OnAccept() function.  Get it?

   Is that what you are looking for?

-=- James.

0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

610 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