🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.ms-windows.programmer.win32
Article #2086

Re: Sockets don't work under VC++ 4.0 ?!!

#2086
From: Tom Brown
Date: Tue, 16 Jan 1996 17:31
63 lines
2759 bytes
In Article<30F8A8B9.279B@metronet.com>, <gavin@metronet.com> writes:
> I finally got around to doing a little Windows Sockets programming in VC++ 
> 4.0 today and was quickly greeted with an ugly problem--I can't get it to 
> create a socket.
> 
> The CSocket::Create() function consistently failed, and 
> CSocket::GetLastError() returned WSAEPROTOTYPE. I tried running the CHATTER 
> sample program, and its socket creation failed with the same error.
> 
> Then I tried tried straight socket API calls (as opposed to using the 
CSocket 
> or CAsyncSocket classes). The "socket" function also failed with the 
> WSAEPROTOTYPE error.
> 
> Finally, I tried some simple sockets code in VC++ 1.52c and VC++ 2.2. The 
> code *worked* in both cases. The *exact same code* works fine when compiled 
> with 2.2 but fails when compiled with 4.0.
> 
> Here's a sample of my test code:
> 
>   WSADATA wsadata;
>   WSAStartup( 0x0101, &wsadata );
> 
>   SOCKET sock;
>   if( INVALID_SOCKET == (sock = socket( PF_INET, SOCK_STREAM, 0 )) )
> 	{
> 	int i = WSAGetLastError();
> 	}
> 
>   WSACleanup();

Hmmm... strange!

First of all, test the return value from WSAStartup, make sure it is 
succeeding!

If so then try this socket call:

	sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
	...

This shouldn't be substantially different from your call, it is just more 
explicit.  Some points:

   - The first parameter to socket() specifies an address family, not a
     protocol family so the use of the AF_ constants is more appropriate.
     The header file defines the PF_ and AF_ values to be the same, but
     you never know...

   - Specifying a specific protocol (TCP in this case) leaves the socket
     library no leeway to misinterpret the kind of socket you want.

Other than this I do not know what could be wrong.  A WSAEPROTOTYPE error 
indicates (according to the spec) that the SOCK_STREAM parameter is not 
available for a PF_INET (AF_INET) address family socket which clearly does not 
make sense.

I have not tried to use 4.0 to build socket apps yet so cannot tell you that 
it absolutely works.

-- Tom
   twb@netmanage.com
Technical Details
Message-ID: <NEWTNews.821818157.6722.twb@browns_too.age.com>
Path: arc1-ca.pugleaf.net!age.com!news
References: <30F8A8B9.279B@metronet.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!age.com!news
From: Tom Brown <twb@netmanage.com>
Newsgroups: comp.os.ms-windows.programmer.win32,comp.lang.c++
Subject: Re: Sockets don't work under VC++ 4.0 ?!!
Date: Tue, 16 Jan 96 10:31:20 PDT
Organization: AGE Logics, Inc., San Diego CA
Message-ID: <NEWTNews.821818157.6722.twb@browns_too.age.com>
References: <30F8A8B9.279B@metronet.com>
NNTP-Posting-Host: browns_too.age.com
Mime-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII
To: gavin@metronet.com
X-Newsreader: NEWTNews & Chameleon -- TCP/IP for MS Windows from NetManage