Created
September 27, 2013 11:47
-
-
Save RklAlx/6727398 to your computer and use it in GitHub Desktop.
Sender
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*NOTA: | |
1) tem que se garantir que o windows.h é compilado sempre após o ws2tcpip.h, | |
caso contrário começa a indicar que há referencias duplicadas. | |
2) Quando se trabalha com sockets tem sempre que se inicializar a WinSockDLL -> tag WSAStartup | |
Send function: | |
http://msdn.microsoft.com/en-us/library/windows/desktop/ms740149%28v=vs.85%29.aspx | |
If no error occurs, send returns the total number of bytes sent, which can be *less* | |
than the number requested to be sent in the len parameter. | |
*/ | |
#include <ws2tcpip.h> | |
#include <windows.h> | |
bool CClient::SendLine(std::string& rMessage) | |
{ | |
int bytes_sent = 0; | |
int total_bytes_sent = 0; | |
while(total_bytes_sent < rMessage.size()) | |
{ | |
bytes_sent = send(m_Socket, (rMessage.c_str() + total_bytes_sent), rMessage.size() - total_bytes_sent, 0); | |
if(bytes_sent == SOCKET_ERROR) | |
{ | |
cout << "Failed. Error: " << WSAGetLastError() << endl; | |
return false; | |
} | |
total_bytes_sent += bytes_sent; | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment