-
January 13th, 2009, 06:41 AM
#1
Broadcast receive problem
Hi...
I have created the UDP socket. I am broadcasting the message to 255.255.255.255 to know which are the machines using this application.
When I debug the program, the broadcasting is successful. But the message is not received....
Can anybody tell why this happened / What is the solution to this.....
Here is my code..........
Code:
oid CModifiedSocketDlg :: OnReceiveBroadcast()
{
TCHAR ReceivedBuf[ 70000 ];
CString SendersIP;
TCHAR m_ScError[25];
UINT SendersPort = 8;
int ChekReceived;
UpdateData(TRUE);
ChekReceived = UDPSockptr -> ReceiveFrom( ReceivedBuf, 69999, SendersIP, SendersPort );
if ( ChekReceived == SOCKET_ERROR )
{
wsprintf( m_ScError, "Failed to create Socket %i Close And Restart application", GetLastError());
AfxMessageBox ( m_ScError );
}
else
{
//TCHAR sazError[256];
//wsprintf(sazError, "OnReceive bytes: %d", ChekReceived);
//AfxMessageBox (sazError);
AfxMessageBox( "I come in OnReceive" );
CString Disp = ReceivedBuf;
m_ReceivedData += Disp;
UpdateData( FALSE );
}
}
I get the error .. "Failed to create the socket 10035, close & restart application"
Then program crashes.
-
January 13th, 2009, 06:59 AM
#2
Re: Broadcast receive problem
What is UDPSockptr?
What is 10035? According to MSDN article "":
The following errors apply to this member function:
- WSANOTINITIALISED A successful AfxSocketInit must occur before using this API.
- WSAENETDOWN The Windows Sockets implementation detected that the network subsystem failed.
- WSAEFAULT The lpSockAddrLen argument was invalid: the lpSockAddr buffer was too small to accommodate the peer address.
- WSAEINPROGRESS A blocking Windows Sockets operation is in progress.
- WSAEINVAL The socket has not been bound with Bind.
- WSAENOTCONN The socket is not connected (SOCK_STREAM only).
- WSAENOTSOCK The descriptor is not a socket.
- WSAEOPNOTSUPP MSG_OOB was specified, but the socket is not of type SOCK_STREAM.
- WSAESHUTDOWN The socket has been shut down; it is not possible to call ReceiveFrom on a socket after ShutDown has been invoked with nHow set to 0 or 2.
- WSAEWOULDBLOCK The socket is marked as nonblocking and the ReceiveFrom operation would block.
- WSAEMSGSIZE The datagram was too large to fit into the specified buffer and was truncated.
- WSAECONNABORTED The virtual circuit was aborted due to timeout or other failure.
- WSAECONNRESET The virtual circuit was reset by the remote side.
Victor Nijegorodov
-
January 13th, 2009, 07:07 AM
#3
Re: Broadcast receive problem
Did you call 'AfxSocketInit ()' in your 'InitInstance ()' ?
-
January 13th, 2009, 07:37 AM
#4
Re: Broadcast receive problem
Originally Posted by Skizmo
Did you call 'AfxSocketInit ()' in your 'InitInstance ()' ?
I have ......
Code:
if (!AfxSocketInit())
{
AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
return FALSE;
}
this loop in the InitInstance()
Will this affect the code????? (I am sorry, if this question is ridiculous, but I have very little knowledge of VC++)
-
January 13th, 2009, 07:40 AM
#5
Re: Broadcast receive problem
AfxSocketInit (as the name says) only init's the socket engine. Nothing more, nothing less, so it shouldn't interfere with the rest of your code.
-
January 13th, 2009, 07:43 AM
#6
Re: Broadcast receive problem
Originally Posted by VictorN
What is UDPSockptr?
What is 10035? According to MSDN article "":
UDPSockptr is the pointer of CInheritSockFunc class which is inherited from CAsyncSocket to use its functions.
I know the meaning of those errors..but dont know the solution.please let me know
-
January 13th, 2009, 07:46 AM
#7
Re: Broadcast receive problem
Originally Posted by Skizmo
AfxSocketInit (as the name says) only init's the socket engine. Nothing more, nothing less, so it shouldn't interfere with the rest of your code.
I guess it is not creating the problem..........
When the debugger comes in the line where the ReceiveFrom(); instruction is present, it gives the error output.
Can you please tell me why it is occuring?
-
January 13th, 2009, 07:48 AM
#8
Re: Broadcast receive problem
Originally Posted by scorrpeio
UDPSockptr is the pointer of CInheritSockFunc class which is inherited from CAsyncSocket to use its functions.
So, it is a global variable?
What a silly design!
I know the meaning of those errors..but dont know the solution.please let me know
Then why don't you want to share your knowleges to not let us search MSDN for this meaningless code numbeer?
OK. because you are so lazy, please read about what to do, when you get this error, here: Windows Sockets Error Codes
Victor Nijegorodov
-
January 14th, 2009, 12:11 AM
#9
Re: Broadcast receive problem
Originally Posted by VictorN
So, it is a global variable?
What a silly design!
Then why don't you want to share your knowleges to not let us search MSDN for this meaningless code numbeer?
OK. because you are so lazy, please read about what to do, when you get this error, here: Windows Sockets Error Codes
I am not lazy but very new in the field of prog, specially VC++.
I have taken the design from the guidance of MS code for a messenger which I downloaded from some site.
In that design ptr is declared as global.
The link you pasted, I already gone through that & tried to implement it, but couldnot.
May be because, I have little knowledge, I cant specify my problem properly. Kindly excuse me for that.
-
January 14th, 2009, 02:20 PM
#10
Re: Broadcast receive problem
Originally Posted by VictorN
So, it is a global variable?
What a silly design!
Victor, try and remember that not everyone that posts here is an expert, otherwise they wouldn't be posting, would they? Sometimes people are just following whatever they can find on google and get stuck.
-
January 15th, 2009, 03:36 AM
#11
Re: Broadcast receive problem
Originally Posted by Alin
Victor, try and remember that not everyone that posts here is an expert, otherwise they wouldn't be posting, would they? Sometimes people are just following whatever they can find on google and get stuck.
I agree and sorry!
...
Although the words "silly design" should be applicable to some MSFT people published such not a good exsample in MSDN.
Victor Nijegorodov
-
January 15th, 2009, 12:47 PM
#12
Re: Broadcast receive problem
From MSDN -
Error 10035 - WSAEWOULDBLOCK - This error is returned from operations on nonblocking sockets that cannot be completed immediately, for example recv when no data is queued to be read from the socket. (emphasis is mine)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|