dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12

Thread: Broadcast receive problem

  1. #1
    Join Date
    Dec 2008
    Posts
    86

    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.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,562

    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

  3. #3
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: Broadcast receive problem

    Did you call 'AfxSocketInit ()' in your 'InitInstance ()' ?

  4. #4
    Join Date
    Dec 2008
    Posts
    86

    Re: Broadcast receive problem

    Quote Originally Posted by Skizmo View Post
    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++)

  5. #5
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    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.

  6. #6
    Join Date
    Dec 2008
    Posts
    86

    Re: Broadcast receive problem

    Quote Originally Posted by VictorN View Post
    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

  7. #7
    Join Date
    Dec 2008
    Posts
    86

    Re: Broadcast receive problem

    Quote Originally Posted by Skizmo View Post
    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?

  8. #8
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,562

    Re: Broadcast receive problem

    Quote Originally Posted by scorrpeio View Post
    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

  9. #9
    Join Date
    Dec 2008
    Posts
    86

    Re: Broadcast receive problem

    Quote Originally Posted by VictorN View Post
    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.

  10. #10
    Join Date
    Feb 2002
    Posts
    3,788

    Re: Broadcast receive problem

    Quote Originally Posted by VictorN View Post
    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.

  11. #11
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,562

    Re: Broadcast receive problem

    Quote Originally Posted by Alin View Post
    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

  12. #12
    Join Date
    Aug 2007
    Location
    Birmingham, UK
    Posts
    360

    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)