Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Sockets in Visual Studio 6 on XP

Reply
Thread Tools

Sockets in Visual Studio 6 on XP

 
 
The Beast
Guest
Posts: n/a
 
      08-26-2004
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
 
Reply With Quote
 
 
 
 
Friedrich Neurauter
Guest
Posts: n/a
 
      08-26-2004

"The Beast" <(E-Mail Removed)> schrieb im Newsbeitrag
news:(E-Mail Removed)...
> 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!


 
Reply With Quote
 
 
 
 
The Beast
Guest
Posts: n/a
 
      08-26-2004
On Thu, 26 Aug 2004 09:27:09 +0200, "Friedrich Neurauter"
<(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is Visual Studio 2005 complict with Visual Studio 2003 rockdale ASP .Net 1 08-23-2006 07:20 PM
Should I write Visual studio 2005 or Visual studio 2003 MCSD =?Utf-8?B?VmlqYXk=?= Microsoft Certification 14 06-30-2006 09:05 AM
Is Visual Studio Team System and Visual Studio Foundation Server are same?. Thirumalai ASP .Net 0 05-22-2006 08:48 AM
visual studio .net 2003 verses visual studio .net 2002 wh ASP .Net 2 01-16-2004 04:54 PM



Advertisments