CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    May 2009
    Posts
    88

    unable to create socket...

    Well am trying to create a port scanner for which am trying to create a socket first and then trying to connect at that particular port but the problem is every time i try to create a socket it returns false.......please help as soon as possible......
    Code:
    BOOL CTrial1Dlg::test (CString IP,UINT nPort)
    {
    	
    	sock* pSocket;
    	pSocket = new sock;
    	ASSERT(pSocket);
    	if (!pSocket->Create())
    	{
    		delete pSocket;
    		pSocket = NULL;
    		MessageBox("hmmm");
    		return FALSE;
    	}
    	
    	while (!pSocket->Connect(IP , nPort))
    		{
    		delete pSocket;
    		pSocket = NULL;
    		return FALSE;
    	}
    	pSocket->Close();
    	delete pSocket;
    	return TRUE;
    }
    above sock is a simple class derived from CSocket class.....

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

    Re: unable to create socket...

    1. Did you ever read the documentation about CSocket::Create in MSDN?
    CSocket::Create
    BOOL Create( UINT nSocketPort = 0, int nSocketType = SOCK_STREAM, LPCTSTR lpszSocketAddress = NULL );

    Return Value

    Nonzero if the function is successful; otherwise 0, and a specific error code can be retrieved by calling GetLastError.
    2. Is there any particular reason to use CSocket class (blocking sockets) rather than CAsyncSocket (non-blocking)?
    Victor Nijegorodov

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

    Re: unable to create socket...

    Did you call AfxSocketInit during the startup of your program ?

  4. #4
    Join Date
    May 2009
    Posts
    88

    Re: unable to create socket...

    not explicilty......can i know how can i do this??

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: unable to create socket...

    Quote Originally Posted by pinnachio View Post
    not explicilty......can i know how can i do this??
    Didn't you open the link Skizmo had provided?
    Or you ignore any documentation at all?
    Victor Nijegorodov

  6. #6
    Join Date
    May 2009
    Posts
    88

    Re: unable to create socket...

    thanks a lot it worked fine and sorry for not going through the link initially......

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured