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
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
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
bool ChangeSocketTimeout(int nHeartBeat) // nHeartBeat - value in milliseconds | |
{ | |
if(setsockopt(m_Socket, SOL_SOCKET, SO_RCVTIMEO, (const char *) &nHeartBeat, sizeof(nHeartBeat)) == SOCKET_ERROR) | |
{ | |
printf("Error: %d\n", WSAGetLastError()); | |
return false; | |
} | |
return true; | |
} |
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
#include <winsock2.h> | |
#include <iostream> | |
using namespace std; | |
bool InitWinsockDLL() | |
{ | |
WSADATA wsaData; | |
// | |
///* Use the MAKEWORD(lowbyte, highbyte) macro declared in Windef.h */ |
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
#include "StdAfx.h" | |
#include "SocketServer.h" | |
#include <iostream> | |
using namespace std; | |
SocketServer::SocketServer() | |
: m_AccepterSocket(INVALID_SOCKET), | |
m_nPort(0), | |
m_dwAccepterThreadID(0) |
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 |
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. |
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> | |
void ShowInfo(struct addrinfo *res) |
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
CMyClient::CMyClient(const char* pIP, unsigned int port) | |
{ | |
m_Socket = INVALID_SOCKET; | |
_snprintf_s(this->m_IP,IP_SIZE,_TRUNCATE,pIP); | |
this->InitSockAddrIn(); | |
} | |
void CMyClient::InitSockAddrIn() | |
{ |
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
#include "C.h" | |
std::shared_ptr<CC> CC::CreateCC(int x) | |
{ | |
return std::make_shared<CC>(CC::Key(),x); | |
} | |
CC::CC(const Key& rk, int xy) | |
{ | |
y = xy; |
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
std::unique_ptr<int> p1(new int(5)); | |
std::unique_ptr<int> p2 = p1; //Compile error. | |
std::unique_ptr<int> p3 = std::move(p1); //Transfers ownership. p3 now owns the memory and p1 is rendered invalid. | |
p3.reset(); //Deletes the memory. | |
p1.reset(); //Does nothing. |
OlderNewer