CodeGuru Forums -
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic Newsletters VB Forums Developer.com


Newest CodeGuru.com Articles:

  • Installing SQL Server 2008
  • Writing UDFs for Firebird Embedded SQL Server
  • [Updated] Shutdown Manager
  • Building Windows Azure Cloud Service Applications with Azure Storage and the Azure SDK

  • Search CodeGuru:
     



    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > Visual C++ Programming
    FAQ Members List Calendar Search Today's Posts Mark Forums Read

    Visual C++ Programming Ask questions about Windows programming with Visual C++ and help others by answering their questions.

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1    
    Old February 24th, 2005, 08:24 AM
    Electroskill Electroskill is offline
    Member
     
    Join Date: Feb 2003
    Posts: 235
    Electroskill is an unknown quantity at this point (<10)
    Socket Notification Sink Error - What is causing this???

    I have an application which receives data from UDP (using CAsyncsocket) and then calls a function in my main dialog. The UDP function works fine. When no errors are received, it calls a function in my main dialog by doing:

    ((CCheckpointDlg*)m_pWnd)->OnReceivedFromSocket();

    which was defined in

    void MySocket::SetParent(CDialog *pWnd)
    {
    m_pWnd=pWnd;
    }

    The function it calls is:

    void CCheckpointDlg::OnReceivedFromSocket()
    {
    CString UMess;
    UMess="UDP Update Received";
    m_diag.AddString(UMess);
    }

    The problem is that I can never get the m_diag list box to addstring. I get an “Unhandled exception” error” when I run from debug or a “Socket Notification Sink” application error when the program executes. What is causing this problem? Is it my listbox or something with my socket? I can’t view the class members of m_diag by using the “.”, and my UDP message is received like this:

    void MySocket::OnReceive(int nErrorCode)
    {
    MySocket UDPRecord;
    CString Message;
    unsigned char Buffer[512]; // Increase in size as needed
    DWORD Error;
    CAsyncSocket::OnReceive(nErrorCode);
    if (nErrorCode)
    {
    Message.Format("OnReceive nErrorCode: %i", nErrorCode);
    AfxMessageBox(Message);
    return;
    }

    UDPRecord.m_Size = ReceiveFrom(Buffer, sizeof Buffer, UDPRecord.m_IPAddress,
    UDPRecord.m_Port);

    //If there is a problem
    if (!UDPRecord.m_Size || UDPRecord.m_Size == SOCKET_ERROR) {
    Error = GetLastError();
    Message.Format("ReceiveFrom error code: %u", Error);
    AfxMessageBox(Message);
    return;
    }
    // process the data

    ((CCheckpointDlg*)m_pWnd)->OnReceivedFromSocket();


    }

    Do you see what the problem is?


    Thanks for looking!

    -Electroskill
    Reply With Quote
      #2    
    Old February 24th, 2005, 12:49 PM
    kuphryn kuphryn is offline
    Elite Member
    Power Poster
     
    Join Date: Feb 2002
    Posts: 5,758
    kuphryn has a spectacular aura about (125+)kuphryn has a spectacular aura about (125+)
    Re: Socket Notification Sink Error - What is causing this???

    Where do you make the call to SetParent()? Post the any call to the list control API such as to create columns.

    Kuphryn
    Reply With Quote
      #3    
    Old February 24th, 2005, 12:57 PM
    Electroskill Electroskill is offline
    Member
     
    Join Date: Feb 2003
    Posts: 235
    Electroskill is an unknown quantity at this point (<10)
    Re: Socket Notification Sink Error - What is causing this???

    Kuphryn,

    Thanks for the response. I am calling the SetParent in my CMySocket class (derived from ASyncSocket. What is driving me crazy is that at first I though this related to the listbox because the debugger only returned a memory exception. Then I tried to execute it without stepping through and I received the "Socket Notification Sink" error. I've done almost this exact same thing before, except my other apps used TCP and this is the first one that used UDP. I didn't think that could make a difference though!

    Thanks,

    Electroskill
    Reply With Quote
      #4    
    Old February 24th, 2005, 01:01 PM
    kuphryn kuphryn is offline
    Elite Member
    Power Poster
     
    Join Date: Feb 2002
    Posts: 5,758
    kuphryn has a spectacular aura about (125+)kuphryn has a spectacular aura about (125+)
    Re: Socket Notification Sink Error - What is causing this???

    Call MySocket's SetParent() from CCheckpointDlg and past its pointer.

    Kuphryn
    Reply With Quote
      #5    
    Old February 24th, 2005, 02:27 PM
    Electroskill Electroskill is offline
    Member
     
    Join Date: Feb 2003
    Posts: 235
    Electroskill is an unknown quantity at this point (<10)
    Re: Socket Notification Sink Error - What is causing this???

    Kuphryn,

    So you're saying take this code:

    void MySocket::SetParent(CDialog *pWnd)
    {
    m_pWnd=pWnd;
    }

    and place it in the CheckpointDlg.cpp? Maybe I am misunderstanding?

    -Electroskill
    Reply With Quote
      #6    
    Old February 24th, 2005, 05:36 PM
    MikeAThon MikeAThon is offline
    Elite Member
    Power Poster
     
    Join Date: Nov 2002
    Location: California
    Posts: 4,123
    MikeAThon has a brilliant future (2000+)MikeAThon has a brilliant future (2000+)MikeAThon has a brilliant future (2000+)MikeAThon has a brilliant future (2000+)MikeAThon has a brilliant future (2000+)MikeAThon has a brilliant future (2000+)MikeAThon has a brilliant future (2000+)MikeAThon has a brilliant future (2000+)MikeAThon has a brilliant future (2000+)MikeAThon has a brilliant future (2000+)MikeAThon has a brilliant future (2000+)
    Re: Socket Notification Sink Error - What is causing this???

    Is this a multi-threaded application?

    Mike
    Reply With Quote
      #7    
    Old February 24th, 2005, 06:28 PM
    Electroskill Electroskill is offline
    Member
     
    Join Date: Feb 2003
    Posts: 235
    Electroskill is an unknown quantity at this point (<10)
    Re: Socket Notification Sink Error - What is causing this???

    MikeAThon- Nope, it's just a single dialog, and it is driving me nuts!!!

    -Electroskill
    Reply With Quote
      #8    
    Old February 24th, 2005, 07:10 PM
    MikeAThon MikeAThon is offline
    Elite Member
    Power Poster
     
    Join Date: Nov 2002
    Location: California
    Posts: 4,123
    MikeAThon has a brilliant future (2000+)MikeAThon has a brilliant future (2000+)MikeAThon has a brilliant future (2000+)MikeAThon has a brilliant future (2000+)MikeAThon has a brilliant future (2000+)MikeAThon has a brilliant future (2000+)MikeAThon has a brilliant future (2000+)MikeAThon has a brilliant future (2000+)MikeAThon has a brilliant future (2000+)MikeAThon has a brilliant future (2000+)MikeAThon has a brilliant future (2000+)
    Re: Socket Notification Sink Error - What is causing this???

    Single "dialog" is not the same thing as single "thread", but I think you meant to confirm that it's single-threaded.

    So, in the following code:
    Code:
    void CCheckpointDlg::OnReceivedFromSocket()
    {
    CString UMess;
    UMess="UDP Update Received";
    m_diag.AddString(UMess);
    }
    what is m_diag and where is it defined?

    And where exactly do you get the "Unhandled exception" error? What is your code executing, and what does the call stack say?

    It might help to post your project's code (with unnecessary files removed, like .clw and .opt)

    Mike
    Reply With Quote
      #9    
    Old February 24th, 2005, 09:07 PM
    Electroskill Electroskill is offline
    Member
     
    Join Date: Feb 2003
    Posts: 235
    Electroskill is an unknown quantity at this point (<10)
    Re: Socket Notification Sink Error - What is causing this???

    MikeAThon.

    m_diag is a ListBox and it is declared in my dialog's class (CheckpointDlg). If I set a breakpoint at the line attempting to add a string to the list box and step through the debug, the following happens:


    -I press a launch button to create the UDP socket (works OK)
    -When a datagram is received, the Receive function is called in MySocket, which is derived from CASyncsockete (works OK)
    -The Receive function calls OnReceive and gets the UDP data (works OK)
    -The function calls OnReceivedFromSocket which is in the dialog's CPP (works OK)
    When the program get to the AddString line, it gives me the unhandled exception error. However, if I just run it in real time, the program will fail with the Socket Notification Sink error. I posted the applicable code snippets below. I created this small program to make sure it will work as a component in my larger app, so there's really nothing else that the program does right now.

    I could post all of the code, but it is on my laptop at work. I had to leave work defeated by this simple problem!!!

    Thanks MikeAThon,

    Electroskill


    Here is the call in the MySocket:
    void MySocket::OnReceive(int nErrorCode)
    {
    MySocket UDPRecord;
    CString Message;
    unsigned char Buffer[512]; // Increase in size as needed
    DWORD Error;
    CAsyncSocket::OnReceive(nErrorCode);
    if (nErrorCode)
    {
    Message.Format("OnReceive nErrorCode: %i", nErrorCode);
    AfxMessageBox(Message);
    return;
    }

    UDPRecord.m_Size = ReceiveFrom(Buffer, sizeof Buffer, UDPRecord.m_IPAddress,
    UDPRecord.m_Port);

    //If there is a problem
    if (!UDPRecord.m_Size || UDPRecord.m_Size == SOCKET_ERROR) {
    Error = GetLastError();
    Message.Format("ReceiveFrom error code: %u", Error);
    AfxMessageBox(Message);
    return;
    }
    // process the data

    ((CCheckpointDlg*)m_pWnd)->OnReceivedFromSocket();


    }

    ((CCheckpointDlg*)m_pWnd)->OnReceivedFromSocket();

    which was defined in

    void MySocket::SetParent(CDialog *pWnd)
    {
    m_pWnd=pWnd;
    }
    Reply With Quote
      #10    
    Old February 24th, 2005, 10:13 PM
    MikeAThon MikeAThon is offline
    Elite Member
    Power Poster
     
    Join Date: Nov 2002
    Location: California
    Posts: 4,123
    MikeAThon has a brilliant future (2000+)MikeAThon has a brilliant future (2000+)MikeAThon has a brilliant future (2000+)MikeAThon has a brilliant future (2000+)MikeAThon has a brilliant future (2000+)MikeAThon has a brilliant future (2000+)MikeAThon has a brilliant future (2000+)MikeAThon has a brilliant future (2000+)MikeAThon has a brilliant future (2000+)MikeAThon has a brilliant future (2000+)MikeAThon has a brilliant future (2000+)
    Re: Socket Notification Sink Error - What is causing this???

    Sorry to be dense, but where are you getting the "socket notification sink" error? Is the error also occurring right when the AddString code is being executed?

    Also, I just noticed that in the following code:
    Code:
    void MySocket::OnReceive(int nErrorCode)
    {
     MySocket UDPRecord;
     CString Message;
     unsigned char Buffer[512]; // Increase in size as needed
     DWORD Error;
     CAsyncSocket::OnReceive(nErrorCode);
     if (nErrorCode) 
     {
      Message.Format("OnReceive nErrorCode: %i", nErrorCode);
      AfxMessageBox(Message);
      return;
     }
    
     UDPRecord.m_Size = ReceiveFrom(Buffer, sizeof Buffer, UDPRecord.m_IPAddress,
     UDPRecord.m_Port);
    
     //If there is a problem
     if (!UDPRecord.m_Size || UDPRecord.m_Size == SOCKET_ERROR) {
      Error = GetLastError();
      Message.Format("ReceiveFrom error code: %u", Error);
      AfxMessageBox(Message);
      return;
     }
     // process the data
    
     ((CCheckpointDlg*)m_pWnd)->OnReceivedFromSocket();
    
    
    }
    you are for some reason creating a second MySocket object on the stack (named UDPRecord) within the OnReceive handler for some other MySocket object. Why are you doing this? Is it OK that UDPRecord is destructed when the OnReceive handler returns? If MySocket is derived from CAsyncSocket, where do you call UDPRecord.Create()? Or do you need to/want to (maybe you only want some internal data structures for UDPRecord and are uninterested in the underlying CAsyncSocket functionality)?

    Mike
    Reply With Quote
      #11    
    Old February 24th, 2005, 10:38 PM
    Electroskill Electroskill is offline
    Member
     
    Join Date: Feb 2003
    Posts: 235
    Electroskill is an unknown quantity at this point (<10)
    Re: Socket Notification Sink Error - What is causing this???

    Mike,

    Thanks for the responses. Yes, the error is received when it tries to process the addstring.

    -Electroskill
    Reply With Quote
      #12    
    Old February 25th, 2005, 10:45 AM
    Electroskill Electroskill is offline
    Member
     
    Join Date: Feb 2003
    Posts: 235
    Electroskill is an unknown quantity at this point (<10)
    Re: Socket Notification Sink Error - What is causing this???

    MikeAThon,

    The socket was created in my CheckpointDlg class:

    void CCheckpointDlg::OnLauncher()
    {
    m_Sock.Create(5361,SOCK_DGRAM);
    }


    Plus, I also reduced my OnReceive function down to this but to no avail:

    void MySocket::OnReceive(int nErrorCode)
    {
    CString Message;
    unsigned char Buffer[512]; // Increase in size as needed
    DWORD Error;
    if (nErrorCode)
    {
    Message.Format("OnReceive nErrorCode: %i", nErrorCode);
    AfxMessageBox(Message);
    return;
    }

    CString myIP;
    UINT m_Port;
    int mySize;
    mySize = ReceiveFrom(Buffer, sizeof Buffer, myIP,
    m_Port);
    ((CCheckpointDlg*)m_pWnd)->OnReceivedFromSocket();
    CCheckpointDlg *pParenter;

    }

    -Thanks,

    Electroskill
    Reply With Quote
      #13    
    Old February 25th, 2005, 11:32 AM
    cvogt61457 cvogt61457 is offline
    Member +
     
    Join Date: Aug 2001
    Location: Texas
    Posts: 645
    cvogt61457 will become famous soon enough (80+)
    Re: Socket Notification Sink Error - What is causing this???

    Please use code tags.

    It makes it easier to read.
    Reply With Quote
      #14    
    Old February 25th, 2005, 01:35 PM
    MikeAThon MikeAThon is offline
    Elite Member
    Power Poster
     
    Join Date: Nov 2002
    Location: California
    Posts: 4,123
    MikeAThon has a brilliant future (2000+)MikeAThon has a brilliant future (2000+)MikeAThon has a brilliant future (2000+)MikeAThon has a brilliant future (2000+)MikeAThon has a brilliant future (2000+)MikeAThon has a brilliant future (2000+)MikeAThon has a brilliant future (2000+)MikeAThon has a brilliant future (2000+)MikeAThon has a brilliant future (2000+)MikeAThon has a brilliant future (2000+)MikeAThon has a brilliant future (2000+)
    Re: Socket Notification Sink Error - What is causing this???

    Electroskill,

    It really is important for you to help us to help you. Please look back over this thread and you'll see that many people who have tried to help have also asked for information, and you did not give most of it. Kuphryn, for example, asked you to post "any call to the list control API such as to create columns" and you did not. I asked you to post the project and you did not. I also asked you to post the call stack around the error and you did not.

    Moreover, your descriptions of the symptoms are not very helpful. In this last post, you said that you made a change "but to no avail". What does that mean, and how is that helpful to us.

    Please give us the tools to help you. Frankly, what you're seeing is probably unrelated to sockets since the error occurs in OnReceivedFromSocket which doesn't use any information from the socket, and it probably is more related to the missing information that Kuphryn asked for. But unless you explain what you're seeing with precision, we can't help.

    Mike
    Reply With Quote
      #15    
    Old February 25th, 2005, 02:06 PM
    Electroskill Electroskill is offline
    Member
     
    Join Date: Feb 2003
    Posts: 235
    Electroskill is an unknown quantity at this point (<10)
    Re: Socket Notification Sink Error - What is causing this???

    MikeAThon,

    Thanks. In reference to Kuphryn's question, maybe I didn't understand it correctly. I took it as a call to LBS_MULTICOLUMN, and my call was LBS_SORT | LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP. Sorry if that was confusing.

    I attached the code in zip below. Here is the call stack when the program stops:

    MFC42D! 5f484cf5()
    CCheckpointDlg::OnReceivedFromSocket() line 199
    MySocket::OnReceive(int 0) line 79
    CAsyncSocket:oCallBack(unsigned int 2956, long 1) line 529
    CSocket::ProcessAuxQueue() line 822
    CSocketWnd::OnSocketNotify(unsigned int 2956, long 1) line 1126
    MFC42D! 5f42f35c()
    MFC42D! 5f42ec98()
    MFC42D! 5f42c839()
    MFC42D! 5f42ccd5()
    MFC42D! 5f49057d()
    USER32! 77e11ef0()
    USER32! 77e1204c()
    USER32! 77e15f69()
    MFC42D! 5f43224f()
    MFC42D! 5f43464f()
    CCheckpointApp::InitInstance() line 65 + 11 bytes
    MFC42D! 5f4335d3()
    WinMain(HINSTANCE__ * 0x00400000, HINSTANCE__ * 0x00000000, char * 0x001327b1, int 1) line 30
    WinMainCRTStartup() line 330 + 54 bytes
    KERNEL32! 7c581af6()

    I cleared out the duplicate reference of UDP record in MySocket but it didn't change the error

    Thanks for your help,

    Electroskill
    Attached Files
    File Type: zip checkpoint3.zip (42.0 KB, 101 views)
    Reply With Quote
    Reply

    Bookmarks
    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > Visual C++ Programming


    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 09:11 PM.



    Acceptable Use Policy

    internet.comMediabistrojusttechjobs.comGraphics.com

    WebMediaBrands Corporate Info


    Advertise | Newsletters | Feedback | Submit News

    Legal Notices | Licensing | Permissions | Privacy Policy


    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
    Copyright WebMediaBrands Inc. 2002-2009