SHARE
TWEET

Untitled

a guest Oct 13th, 2019 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. #include <iostream>
  3. #include <string>
  4. #include <random>
  5. #include <ctime>
  6. #include <vector>
  7. #include <fstream>
  8. #include <WS2tcpip.h>
  9.  
  10. #pragma comment (lib, "ws2_32.lib")
  11.  
  12.  
  13.  
  14. void main(int argc, char* argv[])
  15. {
  16.     WSADATA data;
  17.  
  18.     menu();
  19.  
  20.     WORD version = MAKEWORD(2, 2);
  21.  
  22.     //rozpoczynanie Winsocku
  23.     int wsOk = WSAStartup(version, &data);
  24.     if (wsOk != 0)
  25.     {
  26.         std::cout << "Nie mozna uruchomic Winsocku!" << wsOk;
  27.         return;
  28.     }
  29.  
  30.     //tworzenie struktury servera
  31.     sockaddr_in server;
  32.     server.sin_family = AF_INET; //AF_INET = IPv4 addresses
  33.     server.sin_port = htons(54000); //konwersja z little do big endian
  34.     inet_pton(AF_INET, "127.0.0.1", &server.sin_addr); //konwersja z string na tablice bajtow
  35.  
  36.     SOCKET out = socket(AF_INET, SOCK_DGRAM, 0);
  37.  
  38.     std::string s(argv[0]);
  39.     int sendOk = sendto(out, s.c_str(), s.size() + 1, 0, (sockaddr*)&server, sizeof(server));
  40.  
  41.     if (sendOk == SOCKET_ERROR)
  42.     {
  43.         std::cout << "That didn't work! " << WSAGetLastError() << '\n';
  44.     }
  45.  
  46.     //zamykanie polaczenia
  47.     closesocket(out);
  48.     WSACleanup();
  49. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top