int main(void) { WSADATA Data; SOCKADDR_IN recvSockAddr; SOCKET recvSocket; int status; int numrcv = 0; struct hostent * remoteHost; char * ip; const char * host_name = "pb-homework.appspot.com"; char buffer[MAXBUFLEN]; char myArray[50]; memset(buffer,0,MAXBUFLEN); // Initialize Windows Socket DLL status = WSAStartup(MAKEWORD(2, 2), &Data); if(status != 0) { printf("ERROR: WSAStartup unsuccessful\r\n"); return 1; } // Create socket recvSocket = createSocket(); // Get IP address from host name remoteHost = gethostbyname(host_name); ip = inet_ntoa(*(struct in_addr *)*remoteHost->h_addr_list); printf("IP address is: %s.\n", ip); memset(&recvSockAddr, 0, sizeof(recvSockAddr)); // zero the sockaddr_in structure recvSockAddr.sin_port=htons(PORT); // specify the port portion of the address recvSockAddr.sin_family=AF_INET; // specify the address family as Internet recvSockAddr.sin_addr.s_addr= inet_addr(ip); // specify ip address // Connect connectToRemoteServer(recvSocket, recvSockAddr); // Send request sendRequest(recvSocket, host_name); strcpy(buffer, receiveResponse(recvSocket)); //Send request with secret param sendSecret(recvSocket, host_name, buffer); strcpy(buffer, receiveResponse(recvSocket)); strcpy(myArray, getString(recvSocket, buffer)); strcpy(myArray, arraySorting(myArray, getArraySize(myArray))); //Send POST-request with sorted array sendPOST(recvSocket, host_name, myArray); puts(receiveResponse(recvSocket)); closesocket(recvSocket); WSACleanup(); getchar(); return EXIT_SUCCESS; }
NetWorkClient::NetWorkClient(QObject *parent) : QTcpSocket(parent) , packetSize(-1) { connect(this, SIGNAL(connected()), this, SIGNAL(connectToRemoteServer()) ); connect(this, SIGNAL(readyRead()), this, SLOT(onReadyRead()) ); connect(this, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(onError(QAbstractSocket::SocketError)) ); }