SHARE
TWEET

client

a guest Oct 13th, 2019 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void main(int argc, char* argv[])
  2. {
  3.     WSADATA data;
  4.  
  5.     WORD version = MAKEWORD(2, 2);
  6.  
  7.     //rozpoczynanie Winsocku
  8.     int wsOk = WSAStartup(version, &data);
  9.     if (wsOk != 0)
  10.     {
  11.         std::cout << "Nie mozna uruchomic Winsocku!" << wsOk;
  12.         return;
  13.     }
  14.  
  15.     //tworzenie struktury servera
  16.     sockaddr_in server;
  17.     server.sin_family = AF_INET; //AF_INET = IPv4 addresses
  18.     server.sin_port = htons(54000); //konwersja z little do big endian
  19.     inet_pton(AF_INET, "127.0.0.1", &server.sin_addr); //konwersja z string na tablice bajtow
  20.  
  21.     SOCKET out = socket(AF_INET, SOCK_DGRAM, 0);
  22.  
  23.     std::string s(argv[0]);
  24.     int sendOk = sendto(out, s.c_str(), s.size() + 1, 0, (sockaddr*)&server, sizeof(server));
  25.  
  26.     if (sendOk == SOCKET_ERROR)
  27.     {
  28.         std::cout << "That didn't work! " << WSAGetLastError() << '\n';
  29.     }
  30.  
  31.     //zamykanie polaczenia
  32.     closesocket(out);
  33.     WSACleanup();
  34. }
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top