i wrote a simple socket client and for testing i tried to connect to a http server and send the http command 'GET / HTTP/1.1' but i get nothing back. i've looked through other post, and searched online, from everything i see it should work. here's the code:
Code:target.sin_family = AF_INET; target.sin_addr.s_addr = *((unsigned long *)host->h_addr); sck = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (connect(sck, (SOCKADDR *)&target, sizeof(target)) == SOCKET_ERROR) { cout << "error connecting to target" << endl; closesocket(sck); WSACleanup(); return 0; } char outBuff[BUF_SIZE]; char inBuff[BUF_SIZE]; int bytes_recv; do { cout << "->"; cin.getline(outBuff, BUF_SIZE-2); if (strcmp(outBuff, "quit")==0) break; strcat(outBuff, "\r\n"); if (send(sck, outBuff, strlen(outBuff), 0)) { cout << "send successful" << endl; bytes_recv = recv(sck, inBuff, BUF_SIZE, 0); if (bytes_recv != 0 && bytes_recv != SOCKET_ERROR) { cout << inBuff << endl; } } memset(outBuff, 0, BUF_SIZE); memset(inBuff, 0, BUF_SIZE); } while (true); closesocket(sck); WSACleanup();




Reply With Quote