Sockets in Visual Studio 6 on XP

T

The Beast

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
 
F

Friedrich Neurauter

The Beast said:
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!
 
T

The Beast

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top