Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #define _WINSOCK_DEPRECATED_NO_WARNINGS
  3. #pragma comment(lib, "ws2_32.lib")
  4. #include<stdio.h>
  5. #include<iostream>
  6. #include<winsock2.h>
  7. #include<windows.h>
  8.  
  9. using namespace std;
  10.  
  11. void main()
  12. {
  13.     SetConsoleCP(1251);
  14.     SetConsoleOutputCP(1251);
  15.     WORD wVersionRequested;
  16.     WSADATA wsaData;
  17.     int err;
  18.     wVersionRequested = MAKEWORD(2, 2);
  19.     err = WSAStartup(wVersionRequested, &wsaData);
  20.     if (err != 0) { return; }
  21.  
  22.     while (true)
  23.     {
  24.         SOCKET s = socket(AF_INET, SOCK_STREAM, 0);
  25.         sockaddr_in dest_addr;
  26.         dest_addr.sin_family = AF_INET;
  27.         dest_addr.sin_port = htons(1280);
  28.         dest_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
  29.         connect(s, (sockaddr *)&dest_addr, sizeof(dest_addr));
  30.  
  31.         char buf[100];
  32.    
  33.         cout << "Введите строку:" << endl;
  34.         fgets(buf, sizeof(buf), stdin);
  35.         send(s, buf, 100, 0);
  36.  
  37.         if (recv(s, buf, sizeof(buf), 0) != 0)
  38.         {
  39.             cout << "Полученая строка:" << endl << buf << endl;
  40.         }
  41.        
  42.         closesocket(s);
  43.     }
  44.     WSACleanup();
  45.  
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement