i am coding a network chat client, an di am having trouble with the receive part.
i'm not sure how to get whats received and print it out onto the screen, i think i have to get whats received and place it in the receive buffer then print it to the screen and clare the buffer. but i am not sure how to do this
please give me an ideaCode:for (;;) { gets(sendBuffer); //takes input from keyboard if (strcmp(sendBuffer, "quit") == 0) //if quit was typed then end client { break; } unsigned long messagelength = strlen(sendBuffer); //get size of message messagelength = htonl(messagelength); //fix byte ordering if ((nbytes = send(mysocket, (char*)&messagelength, sizeof(messagelength), 0)) == SOCKET_ERROR) { cout << "Send Failed!" << endl; //send the message size } messagelength = ntohl(messagelength); //refix byte ordering if ((nbytes = send(mysocket, sendBuffer, messagelength, 0)) == SOCKET_ERROR) { cout << "Send Failed!" << endl; //send actual message } gets(receiveBuffer); unsigned long messagesize = strlen(receiveBuffer); messagesize = htonl(messagesize); if ((nbytes = recv(mysocket, (char*)&messagesize, sizeof(messagesize), 0)) == SOCKET_ERROR) { cout << "Receive Failed!" << endl; } messagesize = ntohl(messagesize); if ((nbytes = recv(mysocket, receiveBuffer, messagesize, 0)) == SOCKET_ERROR) { cout << "Receive Failed!" << endl; } }



LinkBack URL
About LinkBacks


