更改为win下跨平台的程序
#include <winsock2.h>
void init_winsock()
{
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD(2,2);
err = WSAStartup( wVersionRequested, &wsaData );
if ( err != 0 ) {
return;
}
if ( LOBYTE( wsaData.wVersion ) != 2 ||
HIBYTE( wsaData.wVersion ) != 2 ) {
WSACleanup();
return;
}
}
CmakeLists.txt 添加 link_libraries(-lws2_32)
-------------------------
WSADATA wsaData;
if (WSAStartup(MAKEWORD(1,1), &wsaData))
return 0;