Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 stupid winsock...
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Pyroguy




PostPosted: Wed Dec 31, 2003 8:20 pm   Post subject: stupid winsock...

i'm just starting experimenting with winsock... but i've been having a problem with the accept function... for some reason i can't figure out it gives me a cannot convert `bool' to `int*' for argument `3' to ` on line 37... can anyone help??? oh yeah this is the server by the way
code:

#include <iostream>
#include <winsock.h>

#define PORT 5000
using namespace std;
int main ()
{
    WSAData wsaData;
    if (WSAStartup(MAKEWORD(1,1), &wsaData) != 1)
    {
        fprintf(stderr, "WSAStartup failed.\n");
        exit(1);
    }
    int mysock = socket(AF_INET, SOCK_STREAM, 0);
    int list_sock;
    struct sockaddr_in sockinfo;
    struct sockaddr_in theirsockinfo;
    sockinfo.sin_family = AF_INET;
    sockinfo.sin_port = htons(PORT);
    sockinfo.sin_addr.s_addr = htonl(INADDR_ANY);
    memset(&(sockinfo.sin_zero),'\0',8);
    if (bind(mysock, (struct sockaddr*)&sockinfo, sizeof(struct sockaddr)) != 0)
    {
        fprintf (stderr, "Error binding socket.\n");
        exit(1);
    }
    if (listen(mysock, 10) != 0)
    {
        fprintf(stderr, "Error listening on socket... isn't bu gay?.\n");
        exit(1);
    }
    int sinsize;
    int datasend, datalen;
    char* data;
    sinsize = sizeof(struct sockaddr_in);
   
    if (list_sock = accept(mysock, (struct sockaddr*)&theirsockinfo, &sinsize != 0)
    {
        fprintf(stderr, "Could not accept request\n");
        exit(1)
    }
    while(1)
    {

        cin<<data<<endl;
        datalen = strlen(data);
        if (datasend = send(list_sock, data, datalen, 0) != 0)
        {
             fprintf(stderr, "Could not send data\n");
             exit(1);
        }
        if (data == "close")
        {
                if (socketclose(list_sock) != 0)
                {
                                fprintf(stderr,"Error closing socket");
                                exit(1);
                }
                if (socketclose(mysock) != 0)
                {
                                fprintf(stderr,"Error closing socket");
                                exit(1);
                }
                break;
        }
    }   
    if (WSACleanup() != 0)
    {
        fprintf(stderr, "WSACleanup failed.\n");
        exit(1);
    }
    return 0;
}
Sponsor
Sponsor
Sponsor
sponsor
Mazer




PostPosted: Wed Dec 31, 2003 8:45 pm   Post subject: (No subject)

hm... from what i see, i have little to no idea about what's going on. my attempts at learning winsock was somewhat succesful even though the program didn't serve it's purpose (curse you stupid school firewall, curse you!). but the way i 'learned' winsock (winsock2 actually) it was used differently. try checking out the networking tutorials at www.gametutorials.com they're really good.
Pyroguy




PostPosted: Sun Jan 04, 2004 1:28 am   Post subject: got it!

yeah i finally found out what my problem was... i didn't have enough )'s to match up with my ('s. on the accept line.. i hate it when that happens....
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: