Created
September 27, 2013 11:46
-
-
Save RklAlx/6727394 to your computer and use it in GitHub Desktop.
Receiver
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 */ | |
#include <ws2tcpip.h> | |
#include <windows.h> | |
DWORD WINAPI CMyObjec::Receiver(LPVOID arg) // Receive From Client | |
{ | |
CMyObject* _this = (CMyObject *) arg; | |
char buffer[1000] = ""; | |
int n_bytes_rcv = 0; | |
while(_this->m_Connected) | |
{ | |
n_bytes_rcv = recv(_this->m_Socket,buffer,sizeof(buffer),0); | |
if(n_bytes == 0) | |
{ | |
// Connection was closed gracefully | |
return 0; | |
} | |
if(n_bytes_rcv < 0) | |
{ | |
cout << "Error: " << WSAGetLastError() << endl; | |
return 1; | |
} | |
buffer[n_bytes_rcv] = '\0'; | |
_this->HandleMessage(buffer); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment