| CodeGuru Home | VC++ / MFC / C++ | .NET / C# | Visual Basic | Newsletters | VB Forums | Developer.com |
|
|||||||
| Visual C++ Programming Ask questions about Windows programming with Visual C++ and help others by answering their questions. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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 |
|
#3
|
|||
|
|||
|
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 |
|
#4
|
|||
|
|||
|
Re: Socket Notification Sink Error - What is causing this???
Call MySocket's SetParent() from CCheckpointDlg and past its pointer.
Kuphryn |
|
#5
|
|||
|
|||
|
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 |
|
#6
|
|||
|
|||
|
Re: Socket Notification Sink Error - What is causing this???
Is this a multi-threaded application?
Mike |
|
#7
|
|||
|
|||
|
Re: Socket Notification Sink Error - What is causing this???
MikeAThon- Nope, it's just a single dialog, and it is driving me nuts!!!
-Electroskill |
|
#8
|
|||
|
|||
|
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);
}
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 |
|
#9
|
|||
|
|||
|
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; } |
|
#10
|
|||
|
|||
|
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();
}
Mike |
|
#11
|
|||
|
|||
|
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 |
|
#12
|
|||
|
|||
|
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 |
|
#13
|
|||
|
|||
|
Re: Socket Notification Sink Error - What is causing this???
Please use code tags.
It makes it easier to read. |
|
#14
|
|||
|
|||
|
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 |
|
#15
|
|||
|
|||
|
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 529CSocket::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 |
![]() |
| Bookmarks |
|
||||||
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|