Sockets in Visual Studio 6 on XP

Discussion in 'C++' started by The Beast, Aug 26, 2004.

  1. The Beast

    The Beast Guest

    I am trying to use a socket and it says that it can not initialize
    it. I have a form with a button that starts this proc and I kept
    commenting things out and debugging until I found that the problem
    happened on the Create() statement, and I used the switch to findout
    what the error was and it comes back "Not Initialized." What could
    the problem be?
    Here is my code:

    void CSocketDlg::OnMail()
    {
    CString Quit = "128.56.22.8";
    unsigned int Error;

    // construct a socket
    CSocket sockClient;

    // create the SOCKET
    if(sockClient.Create( )==0)
    {
    Error = GetLastError();
    switch (Error)
    {
    case WSANOTINITIALISED:
    Quit = "Not Initialized";
    break;
    case WSAENETDOWN:
    Quit = "Net Down";
    break;
    case WSAEAFNOSUPPORT:
    Quit = "Address Not Supported";
    break;
    case WSAEINPROGRESS:
    Quit = "Blocking Operation in Progress";
    break;
    case WSAEMFILE:
    Quit = "File Descriptor Unavailable";
    break;
    case WSAENOBUFS:
    Quit = "No buffer space available";
    break;
    case WSAEPROTONOSUPPORT:
    Quit = "Port not supported";
    break;
    case WSAEPROTOTYPE:
    Quit = "port is wrong type";
    break;
    case WSAESOCKTNOSUPPORT:
    Quit = "Sock type not supported";
    break;
    }

    m_Edit1.Insert(0, Quit);
    UpdateData(FALSE);
    }

    /* seek a connection
    sockClient.Connect("smtp-server.columbus.rr.com", 0);

    if(sockClient.m_hSocket == INVALID_SOCKET)
    {
    m_Edit1.Insert(0, "Invalid Socket");
    UpdateData(FALSE);
    }
    else
    {
    // construct file object
    CSocketFile file(&sockClient);

    // construct an archive
    CArchive arIn(&file, CArchive::load);

    CArchive arOut(&file, CArchive::store);

    // use the archive to pass data:
    arOut << Quit;

    arIn.Close();
    arOut.Close();
    }*/
    sockClient.Close();
    }

    Thank you,
    The Beast
    The Beast, Aug 26, 2004
    #1
    1. Advertising

  2. "The Beast" <> schrieb im Newsbeitrag
    news:...
    > I am trying to use a socket and it says that it can not initialize
    > it. I have a form with a button that starts this proc and I kept
    > commenting things out and debugging until I found that the problem
    > happened on the Create() statement, and I used the switch to findout
    > what the error was and it comes back "Not Initialized." What could
    > the problem be?
    > Here is my code:
    >
    > void CSocketDlg::OnMail()
    > {
    > CString Quit = "128.56.22.8";
    > unsigned int Error;
    >
    > // construct a socket
    > CSocket sockClient;
    >
    > // create the SOCKET
    > if(sockClient.Create( )==0)
    > {
    > Error = GetLastError();
    > switch (Error)
    > {
    > case WSANOTINITIALISED:
    > Quit = "Not Initialized";
    > break;
    > case WSAENETDOWN:
    > Quit = "Net Down";
    > break;
    > case WSAEAFNOSUPPORT:
    > Quit = "Address Not Supported";
    > break;
    > case WSAEINPROGRESS:
    > Quit = "Blocking Operation in Progress";
    > break;
    > case WSAEMFILE:
    > Quit = "File Descriptor Unavailable";
    > break;
    > case WSAENOBUFS:
    > Quit = "No buffer space available";
    > break;
    > case WSAEPROTONOSUPPORT:
    > Quit = "Port not supported";
    > break;
    > case WSAEPROTOTYPE:
    > Quit = "port is wrong type";
    > break;
    > case WSAESOCKTNOSUPPORT:
    > Quit = "Sock type not supported";
    > break;
    > }
    >
    > m_Edit1.Insert(0, Quit);
    > UpdateData(FALSE);
    > }
    >
    > /* seek a connection
    > sockClient.Connect("smtp-server.columbus.rr.com", 0);
    >
    > if(sockClient.m_hSocket == INVALID_SOCKET)
    > {
    > m_Edit1.Insert(0, "Invalid Socket");
    > UpdateData(FALSE);
    > }
    > else
    > {
    > // construct file object
    > CSocketFile file(&sockClient);
    >
    > // construct an archive
    > CArchive arIn(&file, CArchive::load);
    >
    > CArchive arOut(&file, CArchive::store);
    >
    > // use the archive to pass data:
    > arOut << Quit;
    >
    > arIn.Close();
    > arOut.Close();
    > }*/
    > sockClient.Close();
    > }
    >
    > Thank you,
    > The Beast


    make sure you call
    BOOL AfxSocketInit( WSADATA* lpwsaData = NULL );
    to initialize Windows sockets!
    Friedrich Neurauter, Aug 26, 2004
    #2
    1. Advertising

  3. The Beast

    The Beast Guest

    On Thu, 26 Aug 2004 09:27:09 +0200, "Friedrich Neurauter"
    <> wrote:

    >make sure you call
    >BOOL AfxSocketInit( WSADATA* lpwsaData = NULL );
    >to initialize Windows sockets!


    Thank YOU!! That fixed the problem with the sockets!! You would
    think that it would say something about that in the example it gives
    in MSDN, oh well, now I have some other problems to work on, so I may
    be back!! Thank you again!

    The Beast
    The Beast, Aug 26, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. wh
    Replies:
    2
    Views:
    509
    Cowboy \(Gregory A. Beamer\)
    Jan 16, 2004
  2. Thirumalai
    Replies:
    0
    Views:
    655
    Thirumalai
    May 22, 2006
  3. rockdale
    Replies:
    1
    Views:
    600
    Juan T. Llibre
    Aug 23, 2006
  4. xman
    Replies:
    0
    Views:
    488
  5. xman
    Replies:
    1
    Views:
    592
    Victor Bazarov
    Aug 17, 2005
Loading...

Share This Page