http://GameProgrammer.Com

Programming

GP Mailing List
     Thread Index
     Date Index

ATXGPSIG List
     Thread Index
     Date Index

Google
>

Home

Wise2Food



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Some code ( tcpip programing )



The reason is because WSAStartup returns 0 if it was successful:

from the MSDN:

Return Values
The WSAStartup function returns zero if successful. Otherwise, it returns
one of the error codes listed below.

An application cannot call WSAGetLastError to determine the error code as is
normally done in Windows Sockets is WSAStartup fails. The WS2_32.DLL will
not have been loaded in the case of a failure so the client data area where
the "last error" information is stored could not be established


--

therefore you will need to change your if statement to:
if (!WSAStartup(MAKEWORD(1, 1),&wsaData) != 0)
{
...

or alternatively do something like this (also from MSDN :)

WORD wVersionRequested;
WSADATA wsaData;
int err;

wVersionRequested = MAKEWORD( 2, 0 );

err = WSAStartup( wVersionRequested, &wsaData );
if ( err != 0 ) {
    /* Tell the user that we couldn't find a usable */
    /* WinSock DLL.                                  */
    return;
}

/* Confirm that the WinSock DLL supports 2.0.*/
/* Note that if the DLL supports versions greater    */
/* than 2.0 in addition to 2.0, it will still return */
/* 2.0 in wVersion since that is the version we      */
/* requested.                                        */

if ( LOBYTE( wsaData.wVersion ) != 2 ||
        HIBYTE( wsaData.wVersion ) != 0 ) {
    /* Tell the user that we couldn't find a usable */
    /* WinSock DLL.                                  */
    WSACleanup( );
    return;
}

/* The WinSock DLL is acceptable. Proceed. */


Paul Robson

> -----Original Message-----
> From: gameprogrammer-owner@gameprogrammer.com
> [mailto:gameprogrammer-owner@gameprogrammer.com]On Behalf Of qdlaty
> Sent: Sunday, October 03, 1999 7:36
> To: gameprogrammer@gameprogrammer.com
> Subject: Some code ( tcpip programing )
>
>
> Hello group!
>
> I've just started writing some basic multiplayer game, and I have two
> quastions about tcpip programing.
>
> 1. Why this program doesn't work? When I run it, he tells me that he cant
> init socket. Why?
>
>
> #include  <windows,.h>
>
> #include <winsock.h>
> #include <stdio.h>
>
> int server_socket;
> struct sockaddr_in s_in;
>
> void main(void)
> {
> WSAData wsaData;
> if (WSAStartup(MAKEWORD(1, 1),&wsaData) != 0)
> {
>   printf("Error while WSAStartup()");
>   return;
> }
>
> memset(&s_in,0,sizeof(s_in));
>
> s_in.sin_family = AF_INET;
> s_in.sin_addr.s_addr = INADDR_ANY;
> s_in.sin_port = htons(21);
>
> server_socket = socket(AF_INET,SOCK_STREAM,0);
>
> if(server_socket = INVALID_SOCKET)
> {
>   printf(" Could not init socket. Error %i \n",server_socket);        //
> This is where program return error
>   return;
> }
> printf("All ok");
> return;
> }
>
> I compile it under VC++ 5.0
>
> 2. Where can I find some good tuts about network programing under
> win9x/nt?
> ( links..)
>
> E-mail:      qdlaty@box43.gnet.pl
> UIN: 47212456
>
>
>
>
>
> -------------------------------------------------------------------------
> SKorzyStaj z WiELKiEj PrOmOcji !!!  NiE waHaj siE !!!
>         ZaloZ NajTaNiej SwOj wlASnY SeRweR, doMenE, sKLeP ...
>                 http://www.virgo.com.pl
>
> =================================================================
> The GameProgrammer.Com mailing list is for the open discussion
> of any topic related to the art, science, and business of
> programming games. This list is especially tolerant of beginners.
> We were all beginners once
>
> To SUBSCRIBE or UNSUBSCRIBE please visit:
> http://gameprogrammer.com/mailinglist.html
>

=================================================================
The GameProgrammer.Com mailing list is for the open discussion
of any topic related to the art, science, and business of
programming games. This list is especially tolerant of beginners.
We were all beginners once

To SUBSCRIBE or UNSUBSCRIBE please visit:
http://gameprogrammer.com/mailinglist.html