#ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN #endif #include "iostream" #include "conio.h" #include "windows.h" #include "winsock2.h" #include "string" #pragma comment(lib, "Ws2_32.lib") using namespace std; int main() { WSAData wsaData; WORD DllVersion = MAKEWORD(2,2); int startup_RetVal = WSAStartup(DllVersion, &wsaData); SOCKET sSocket = socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP); SOCKADDR_IN addr; addr.sin_addr.s_addr = inet_addr("127.0.0.1"); addr.sin_family = AF_INET; addr.sin_port = htons(2222); bind(sSocket,(SOCKADDR*)&addr, sizeof(addr)); char buf[400] = {0}; while (recvfrom(sSocket, buf, 400, NULL, NULL, NULL) > 0) { cout << buf; } cout << "end"; _getch(); return 0; }
recvfrom
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)