How to send a message to a client using winsock2? An example is sending a message to the server, and you need something that the server says, did it receive a message? How to implement reception of the message from the server?
2 answers
Look at the article, an example of working with WinSocks2 (client \ server) is described. http://www.binarytides.com/winsock-socket-programming-tutorial/
- For sending messages, send is used, for receiving, respectively, recv. On the server, you can also send messages, and read on the client. - QuaternioNoir
|
Here, for example, something like this:
do { iResult = recv(ClientSocket, recvbuf, recvbuflen, 0); if (iResult > 0) { printf("Bytes received: %d\n", iResult); // Echo the buffer back to the sender iSendResult = send( ClientSocket, recvbuf, iResult, 0 ); if (iSendResult == SOCKET_ERROR) { printf("send failed with error: %d\n", WSAGetLastError()); closesocket(ClientSocket); WSACleanup(); return 1; } printf("Bytes sent: %d\n", iSendResult); } This is all in server code.
|