By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,849 Members | 2,164 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,849 IT Pros & Developers. It's quick & easy.

Sockets in Visual Studio 6 on XP

P: n/a
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
Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"The Beast" <Ob********@columbus.rr.com> schrieb im Newsbeitrag
news:eh********************************@4ax.com...
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!
Jul 22 '05 #2

P: n/a
On Thu, 26 Aug 2004 09:27:09 +0200, "Friedrich Neurauter"
<fr*****************@eunet.at> 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
Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.