Can you guys please help me with what the code does?I think its part of a program.Im really new to C (a week of studying) so Id be really glad if u helped.Also Im sorry if this isn't the right place to post this.
This is the code :
Code:
SOCKADDR_IN address;
SOCKET client;
WSADATA data;
if (WSAStartup(MAKEWORD(1,1), &data) != 0) {
throw( "HttpCommunicator00131" );
return;
}
struct hostent *host = gethostbyname( HOST );
if (host == NULL) {
WSACleanup();
throw( "HttpCommunicator00132" );
return;
}
client = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (client == INVALID_SOCKET) {
WSACleanup();
throw( "HttpCommunicator00133" );
return;
}
memset(&address, 0, sizeof(address));
address.sin_addr.s_addr = *((unsigned long*)host->h_addr);
address.sin_family = AF_INET;
address.sin_port = htons( PORT );
if (connect(client, (LPSOCKADDR)&address, sizeof(address)) != 0) {
closesocket( client );
WSACleanup();
throw( "HttpCommunicator00134" );
return;
}
char parameters[ HTTP_PARAMETERS_BUFFER_SIZE ] = "";
sprintf(parameters, "symbol=%s&period=%d", symbol, period);
sprintf(buffer, "POST %s HTTP/1.0\nHost: %s\r\nContent-Length: %d\r\nConnection: Keep-Alive\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\n%s\r\n", LOAD_TRAINING_SET_SCRIPT, HOST, strlen(parameters), parameters);
if (send(client, buffer, strlen(buffer), 0) == SOCKET_ERROR) {
closesocket( client );
WSACleanup();
throw( "HttpCommunicator00135" );
return;
}
int numberOfBytes = recv(client, buffer, BUFFER_SIZE-1, MSG_WAITALL);
if (numberOfBytes == SOCKET_ERROR) {
closesocket( client );
WSACleanup();
throw( "HttpCommunicator00136" );
return;
}
buffer[ numberOfBytes ] = '\0';