Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: winsock / socket( ) woes

Author: Dan Newman

Date: 00:49:38 03/16/00

Go up one level in this thread


On March 15, 2000 at 20:16:16, James Swafford wrote:

>I'm at the point now that I'm ready to set up data
>exchange between my Windows GUI and linux based
>console engine.
>
>In the GUI, I've called the WSASTARTUP( ) function,
>and it didn't produce any errors.  The socket function
>refuses to create a SOCKET.
>
>Here's the proto for socket():
>
>SOCKET socket(int address_family,int connection_type,int protocol);
>
>I'm trying to use PF_INET (AF_INET) for the address family,
>of course.  I'd prefer a connection oriented connection,
>so I'm using SOCK_STREAM next.  Regardless of what I try
>for protocol (TCP, etc.), I get a -1 from WSALASTERROR.
>
>I don't have a network adapter in the piece right now, so
>I'm not sure if that's the problem.  Seems to me that I should
>at least be able to create the socket, just not bind it.
>
>Help greatly appreciated.
>
>--
>James

I don't think not having a network adapter should hurt since the
connection could go out the usual PPP link.  But then I've
always had a network adapter in my computers when doing socket
programming...

Anyway, I tried this little piece of (C++) code out and it seems to
work fine on my machine:

/*
    Testing winsock...
*/
#include <windows.h>
#include <stdio.h>
#include <winsock.h>

int main()
{
    printf("Initializing WinSock\n");
    WORD vers = MAKEWORD( 1, 1);
    WSADATA wsadata;
    int ret = WSAStartup( vers, &wsadata);
    if( ret != 0 ) {
        printf("Error: couldn't initialize winsock\n");
        return -1;
    }
    if( wsadata.wVersion != vers ) {
        printf("Error: winsock version %d.%d not supported",
          (int)LOBYTE( vers), (int)HIBYTE( vers));
        WSACleanup();
        return -1;
    }
    printf("WinSock initialized\n");

    //
    // Create a socket.
    //
    SOCKET sd = socket( AF_INET, SOCK_STREAM, 0);
    if( sd == INVALID_SOCKET ) {
        printf("Failed to create a socket\n");
        WSACleanup();
        return -1;
    }
    printf("Created a socket\n");

    // Do something....

    closesocket( sd);
    WSACleanup();
    return 0;
}

The parameters to socket() are the ones that I've always used
before, so I'm not sure what the zero for the protocol argument
means...

-Dan.



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.