Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 707713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:18:34+00:00 2026-05-14T04:18:34+00:00

My program has one dialog and two sockets. Both sockets are derived from CAsyncSocket,

  • 0

My program has one dialog and two sockets. Both sockets are derived from CAsyncSocket, one is for listening, other is for receiving data from client. My program crashes when client tries to connect to server application and server needs to initialize receiving socket.

This is my MFC dialog class.

class CFileTransferServerDlg : public CDialog
{
   ...
   ListeningSocket ListenSock;
   ReceivingSocket* RecvSock;
   void OnAccept(); // called when ListenSock gets connection attempt
   ...
};

This is my derived socket class for receiving data that calls parent dialogs method when event is signaled.

class ReceivingSocket : public CAsyncSocket
{
   ...
   CFileTransferServerDlg* m_pDlg; // for accessing parent dialogs controls
   virtual void OnReceive(int nErrorCode);
   ...
}

ReceivingSocket::ReceivingSocket()
{
}

This is dialogs function that handles incoming connection attempt when listening socket gets event notification. This is where the crash happens.

void CFileTransferServerDlg::OnAccept()
{   
   RecvSock = new ReceivingSocket;   /* CRASH */
}

OR

void CFileTransferServerDlg::OnAccept()
{   
   ReceivingSocket* tmpSock = new ReceivingSocket;
   tmpSock->SetParentDlg(this);

   CString message;
   if( ListenSock.Accept(*tmpSock) )  /* CRASH */
   {
      message.LoadStringW(IDS_CLIENT_CONNECTED);
      m_txtStatus.SetWindowTextW(message);
      RecvSock = tmpSock;
   }
}

My program crashes when I try to create a socket for receiving file sent from client application. OnAccept starts when Listening socket signals incoming connection attempt, but my application then crashes. What could be wrong?
Error in debug mode:

Unhandled exception at 0x009c30e1 in FileTransferServer.exe: 0xC0000005: Access violation reading location 0xccccce58.

UPDATE:

I edited code a little and I’ve found that inside sockcore.cpp where Accept is defined, program failes on this line of code:

ASSERT(rConnectedSocket.m_hSocket == INVALID_SOCKET);

I don’t understand how that can happen. ReceivingSocket class is somehow not getting constructed right. I derive it from CAsyncSock, leave constructor empty, and no matter where I create it, on stack or on heap, it always crashes.

Here is complete project, both client and server, if anyone can take a look at it I would be really grateful. I apologize for the comments, they are in Croatian.

Visual Studio project

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T04:18:34+00:00Added an answer on May 14, 2026 at 4:18 am

    I’ve looked into your code. The issue seems to be that you never call ListeningSocket::SetParentDlg(CFileTransferServerDlg* parent). Since you also do not initialize the m_pDlg pointer in the ListeningSocket constructor, it has random values and the program might crash here and there when you access this pointer. (I had also a crash but slightly at another location than you pointed out.)

    I’ve changed it this way:

    In ListeningSocket.h changed the constructor:

    ListeningSocket(CFileTransferServerDlg* parent);
    

    Also in ListeningSocket.cpp:

    ListeningSocket::ListeningSocket(CFileTransferServerDlg* parent)
       : m_pDlg(parent)
    {
    }
    

    Constructor of CFileTransferServerDlg changed this way:

    CFileTransferServerDlg::CFileTransferServerDlg(CWnd* pParent /*=NULL*/)
       : CDialog(CFileTransferServerDlg::IDD, pParent),
         ListenSock(this)
    {
        m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
    }
    

    Crash disappeared.
    Other ways are possible of course.

    Really nice little programs, by the way 🙂 I’ll delete them of course now since I can’t probably afford the license fees 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 381k
  • Answers 381k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer COUNT(*) counts all rows in the result set (or group… May 14, 2026 at 10:14 pm
  • Editorial Team
    Editorial Team added an answer try ${$test.$i} = value EDIT: http://php.net/manual/en/language.variables.variable.php May 14, 2026 at 10:14 pm
  • Editorial Team
    Editorial Team added an answer In your php, you can set the CURLOPT_VERBOSE variable: curl_setopt($curl,… May 14, 2026 at 10:14 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.