a problem in socks.h

Posted by janathan on Stack Overflow See other posts from Stack Overflow or by janathan
Published on 2010-05-13T19:11:56Z Indexed on 2010/05/13 19:14 UTC
Read the original article Hit count: 354

Filed under:
|
|
|

i use this (http://www.codeproject.com/KB/IP/Socks.aspx) lib in my socket programing in c++ and copy the socks.h in include folder and write this code:

include

include

include

include

include

include "socks.h"

define PORT 1001 // the port client will be connecting to

define MAXDATASIZE 100

static void ReadThread(void* lp); int socketId;

int main(int argc, char* argv[]) {

    const char temp[]="GET / HTTP/1.0\r\n\r\n";

    CSocks cs;
    cs.SetVersion(SOCKS_VER4);
    cs.SetSocksPort(1080);
    cs.SetDestinationPort(1001);
    cs.SetDestinationAddress("192.168.11.97");

    cs.SetSocksAddress("192.168.11.97");
    //cs.SetVersion(SOCKS_VER5);
    //cs.SetSocksAddress("128.0.21.200");



    socketId = cs.Connect();

    // if failed
    if (cs.m_IsError)
    {
        printf( "\n%s", cs.GetLastErrorMessage());
        getch();
        return 0;
    }

    // send packet for requesting to a server
    if(socketId > 0)
    {
        send(socketId, temp, strlen(temp), 0);

        HANDLE ReadThreadID;                                            // handle for read thread id
        HANDLE handle;                                                  // handle for thread handle

        handle = CreateThread ((LPSECURITY_ATTRIBUTES)NULL,             // No security attributes.
                                (DWORD)0,                               // Use same stack size.
                                (LPTHREAD_START_ROUTINE)ReadThread,     // Thread procedure.
                                (LPVOID)(void*)NULL,                    // Parameter to pass.
                                (DWORD)0,                               // Run immediately.
                                (LPDWORD)&ReadThreadID);        

        WaitForSingleObject(handle, INFINITE);
    }
    else
    {
        printf("\nSocks Server / Destination Server not started..");
    }
    closesocket(socketId);
    getch();

    return 0;

}

// Thread Proc for reading from server socket. static void ReadThread(void* lp) {

    int numbytes; 
    char buf[MAXDATASIZE];

    while(1)
    {

        if ((numbytes=recv(socketId, buf, MAXDATASIZE-1, 0)) == -1)
        {
                printf("\nServer / Socks Server has been closed Receive thread Closed\0");
                break;
        }
        if (numbytes == 0) break;
            buf[numbytes] = '\0';
            printf("Received: %s\r\n",buf);
            send(socketId,buf,strlen(buf),0);
    }

}

but when compile this i get an error . pls help me thanks

© Stack Overflow or respective owner

Related posts about c++

Related posts about socket